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.

Examples
Input
6 3
1 1 1 0 1 0
Output
3
Input
5 2
0 0 0 1 0
Output
1
Note
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.

C语言版本一

#include <stdio.h>
#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {int n,a;int z[110];int i,j;scanf("%d%d",&n,&a);for(i=0;i<n;i++){scanf("%d",&z[i]);}a-=1;int count=0;//if (z[a]==1)count+=1;for(i=0;i<=n/2;i++){if(z[a-i]==z[a+i]&&z[a-i]==1){if(i==0)count+=1;else count+=2;}if(a-i<=0||a+i>=n-1)break;}if(a-i<=0&&a+i<n-1){for(j=a+i+1;j<n;j++){if(z[j]==1)count+=1;}}else if(a-i>0&&a+i>=n-1){for(j=0;j<a-i;j++){if(z[j]==1)count+=1;}}printf("%d\n",count);return 0;
}

C++版本一

#include<cstdio>
#include<cstring>
const int MYDD=1103;int main() {int n,a;while(scanf("%d%d",&n,&a)!=EOF) {int c[MYDD];//citymemset(c,0,sizeof(c));for(int j=1; j<=n; j++)scanf("%d",&c[j]);int ans=0;for(int j=1; j<=n; j++) {if(c[j]) {//当前城市有小偷int other=a-(j-a);if(other<1||other>n||c[other])ans++;}}printf("%d\n",ans);}return 0;
}

Bear and Finding Criminals相关推荐

  1. Bear and Finding Criminals (模拟)

                                          Bear and Finding Criminals There are n cities in Bearland, num ...

  2. D - Bear and Finding Criminals

    Description There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long ro ...

  3. 服务器打印文档 图片显示是叉,Lodop背景图无图片时显示放大叉号问题

    SEO优化---学会建立高转化率的网站关键词库 想要优化好一个网站,行业的分析,以及关键词的挖掘是必要的,有一定的关键词排名了,但是转化率和流量方面却很不理想这种情况大部分是只注重了有指数的关键词排名 ...

  4. 签到 2016.6.9

    1.CodeForces 337A Puzzles 题意: ①在有m个整数的集合中 ②找到有n个整数的子集 ③再比较这些子集中元素的最大值与最小值的差值 ④输出最小的差值 解题思路: ①将集合中的元素 ...

  5. E. B. Browning: Sonnets from the Portuguese

    01 我想起,当年希腊的诗人曾经歌咏: I thought once how Theocritus had sung 年复一年,那良辰在殷切的盼望中 Of the sweet years, the d ...

  6. Nature计算社会科学特刊:如何对21世纪人类社会进行有意义的度量?

    来源:集智俱乐部本文约16000字,建议阅读20+分钟 本文为你介绍构建新的度量方式,将不可测量的变量变得可测量. [ 导语 ] 在数字时代,我们的社交.运动.购物等日常行为每时每刻都在生成大量数据. ...

  7. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  8. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  9. Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial[转]

    Finding iPhone Memory Leaks: A "Leaks" Tool Tutorial by OWEN GOSS on 12. FEB, 2009 in RESO ...

最新文章

  1. 学习Python往哪个方向发展好
  2. 使用C/C++发展Web系统开源
  3. Java功底之static、final、this、super
  4. 10-10数组的介绍
  5. 行为扩展以及插件机制
  6. java里面怎么添加表约束_alter table添加表约束
  7. Log4j2发新版本2.16.0,加固漏洞防御,不想被攻击,就赶快更新啦!
  8. 四川大学计算机专业调剂,2019四川大学计算机学院考研调剂信息(第二批)
  9. Spring的基于AspectJ的AOP开发——Spring AOP(五)
  10. 计算机上硬盘驱动器,什么是计算机硬盘驱动器?它有什么作用?如何维护?
  11. 中兴B860AV2.1U,联通版本,强刷固件线刷包
  12. Intel SGX背景、其他可信计算技术和TEE技术(翻译自Intel SGX Explained)
  13. Nginx 安装部署以及负载均衡
  14. 爬虫进阶-如何进行app爬取
  15. 腾讯面试题、智力题、Java:小Q的父母要出差N天,走之前给小Q留下了M块巧克力
  16. 深度学习中的对抗损失怎么使用
  17. fpu测试_解毒盖世G600散热器,3900X超频测试能不能压住?
  18. android 编译器indel,Overview of the HbbTV compliant browser upgrade on Android based DTV platform
  19. 嵌入式开发常见宏定义
  20. 使用K-邻近算法实现手写数字识别系统

热门文章

  1. python判断点在直线的哪一侧_判断点在直线的哪一侧
  2. antd upload手动上传_Flask上传文件
  3. HTML5唐四薪,8文件存取组件课件.ppt
  4. java五子棋用到的类_JAVA五子棋用到的知识点以及方法类有哪些?
  5. 如何用python实现自动化_如何使用Python实现自动化水军评论
  6. 在WPS中提取出的照片在哪找_WPS技巧 | 找不到合适的配图?教你一招搞定
  7. java面向对象计算器怎么写_Java对象简单实用案例之计算器实现代码
  8. androidstudio build tools安装_如何导入Android Studio(AS)项目
  9. linux 空格函数,linux c语言的split函数和空格处理函数
  10. 全国计算机二级准考证贵州,贵州计算机二级考试准考证打印时间