B. Bear and Finding Criminals

题目连接:

http://www.codeforces.com/contest/680/problem/B

Description

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.

Sample Input

6 3

1 1 1 0 1 0

Sample Output

3

Hint

题意

有6个城市,有一个警察在a,有一个探测器,可以探测到距离他为i的地方有多少个歹徒。

现在给你每个城市的歹徒数量,最多为1

问你这个警察能够确认歹徒的所在的歹徒,一共有多少个

题解:

模拟一下就好了,如果左右都没有越界的话,那么必须左右都得有歹徒

否则就必须其中一边越界才行。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n,a,p[maxn];
int main()
{
scanf("%d%d",&n,&a);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
int ans = p[a];
for(int i=0,l=a-1,r=a+1;l>=1||r<=n;l--,r++){
if(l>=1&&r<=n){
if(p[l]&&p[r])ans+=2;
}
else if(l>=1)ans+=p[l];
else if(r<=n)ans+=p[r];
}
cout<<ans<<endl;
}

最新文章

  1. 加密web.config
  2. Rational Rose 2007 破解版安装过程
  3. Redis 初
  4. 轻量级应用开发之(02)UIView
  5. POJ 1401 Factorial
  6. Android:仿微信开场切换界面
  7. 【转载】如何在C语言中调用shell命令
  8. ARM学习笔记12——GNU ARM汇编伪操作
  9. js中||和&amp;&amp;的用法
  10. 动态添加div及对应的js、css文件
  11. TCP/IP入门(1) --链路层
  12. P2685 [TJOI2012]桥
  13. GitHub-暂存区与版本回退
  14. python:数据类型dict
  15. php中Redis的扩展
  16. Vue中 v-html 与 v-text 的区别
  17. go反射的规则
  18. Java项目体验
  19. Xming 多屏选项
  20. 【C#】App_LocalResources实现多语言

热门文章

  1. ### mysql系统结构_3_Mysql_Learning_Notes
  2. ASP.NET MVC 5使用Filter过滤Action参数防止sql注入,让你代码安全简洁
  3. 自动化测试Robotium获取当前页面的activity,用于判断是否进入这个页面
  4. 转载:Google 官方应用架构的最佳实践指南 赞&#128077;
  5. Django 2.0.3安装-压缩包方式
  6. JS可以监控手机的返回键吗?
  7. URL的井号
  8. Centos之文件搜索命令locate
  9. Linux学习笔记:ps -ef、ps aux、kill -9
  10. php判断是否是ajax提交 方法