CodeForces 680A 680B

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/haohaoxuexilmy/article/details/81171090

680A:Bear and Five Cards

简单判断 计算

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[5],sum,i,flag,j1,j2;
	while(scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF)
	{
		sum=0;flag=0;j1=0;j2=0;
		sort(a,a+5);
		for(i=0;i<5;i++)
		{
			sum+=a[i];
		  if(a[i]==a[i+1]&&a[i+1]!=a[i+2])
		  {
		  	if(a[i]>flag)   flag=a[i];j1=2*a[i];
		  }
		  if(a[i]==a[i+1]&&a[i]==a[i+2])
		  {
		  	j2=3*a[i];
		  }
		} 
		if(j1>j2)  sum-=j1;
		else sum-=j2;
		printf("%d\n",sum);
	}
	return 0;
}

 680B:Bearing and Finding Criminals

There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|.

Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.

Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.

You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

Input

The first line of the input contains two integers n and a (1 ≤ a ≤ n ≤ 100) — the number of cities and the index of city where Limak lives.

The second line contains n integers t1, t2, ..., tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Output

Print the number of criminals Limak will catch.

Examples

Input

6 3
1 1 1 0 1 0

Output

3

Input

5 2
0 0 0 1 0

Output

1

 捉贼:要确定警察是在前半段还是后半段,以他为对称轴计算到一边到顶,后计算剩余的地方。

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a,i,t[105],begin=0,b=0,end=0,count=0;
	scanf("%d%d",&n,&a);
	for(i=0;i<n;i++)
	{
		scanf("%d",&t[i]);
	}
	if(t[a-1]==1)
	{
		count++;
    }
    if(2*a>n) {
	begin=2*a-n-1;b=0;end=begin;}
    else {
	begin=0;b=2*a-1;end=n;}
	for(i=begin;i<a-1;i++)
	{
	    if(t[i]+t[a-i+a-2]==2) count+=2;
	} 
	for(i=b;i<end;i++)
	{
		if(t[i]==1) count++;
	}
	printf("%d\n",count);
	return 0;
}

 

展开阅读全文

没有更多推荐了,返回首页