Codeforces Round #356 (Div. 2) B Bear and Finding Criminals
来源:互联网 发布:华讯网络北京怎么样 编辑:程序博客网 时间:2024/05/18 17:59
思路:其实并没怎么看懂题目....不过瞎搞搞就过啦
#include<bits\stdc++.h>using namespace std;int a[105];int main(){ int n,p;scanf("%d%d",&n,&p);for(int i = 1;i<=n;i++)scanf("%d",&a[i]);int l=p-1,r=p+1;int ans = 0;if(a[p]==1)ans++;while(l>=1 && r<=n){ if(a[l]&&a[r]){ans+=2;}l--;r++;}while(l>=1){if(a[l])ans++;l--;}while(r<=n){if(a[r])ans++;r++;}cout << ans << endl;}
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.
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.
Print the number of criminals Limak will catch.
6 31 1 1 0 1 0
3
5 20 0 0 1 0
1
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.
- There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city.
- There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city.
- There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
- Codeforces Round #356 (Div. 2) B Bear and Finding Criminals
- Codeforces-Round-#356-(Div.-2)-Bear-and-Finding-Criminals
- ★【16.6.2】Codeforces Round #356 (Div. 2) B. Bear and Finding Criminals
- Codeforces Round #356 (Div. 2)-B. Bear and Finding Criminals(模拟)
- B. Bear and Finding Criminals
- CodeForces 680B Bear and Finding Criminals(捉小偷)
- CodeForces 680B Bear and Finding Criminals 简单模拟
- Codeforces 680B Bear and Finding Criminals【模拟】
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- code force A. Bear and Five Cards&B. Bear and Finding Criminals
- codeforces680B之Bear and Finding Criminals
- Codeforces Round #356 (Div. 2) A - Bear and Five Cards
- Codeforces Round #356 (Div. 2)-C. Bear and Prime 100
- Codeforces-Round-#356-(Div.-2)-Bear-and-Five-Cards
- Codeforces Round #356 (Div. 2) Bear and Square Grid
- Codeforces Round #356 (Div. 2)-C. Bear and Prime 100
- 122. Best Time to Buy and Sell Stock II
- Java中选择排序的代码实现
- Android:Dagger2学习之由浅入深
- 使用lame转换mp3时,出现libmp3lame missing required architecture x86_64
- oj数据结构代码(前半期+后半期)
- Codeforces Round #356 (Div. 2) B Bear and Finding Criminals
- Ikki's Story IV - Panda's Trick_poj3207_2-sat
- orcle数据库system口令忘记怎么办
- zynq ALSA
- DataReader与DataSet
- C#日记——委托
- Java Android开发小知识
- zookeeper入门-整理版
- Android Jni反射Java方法,弹出对话框