Bear 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

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.

大致题意:一个警察住在某个城市,他要抓各个城市的小偷,现在用一个BCD可以知道那个城市里一定有小偷。

(一定能确定该城市有小偷的几种情况:

1.警察所住城市有小偷,则一定能检测到

2.警察所住城市的左面和右面位置若都不为0,则说明两座城市都有小偷

3.警察所在城市的一边检测到有小偷,但在另一边已经没有城市了,则说明该城市一定有小偷)

第一次做的时候,从警察所在城市向两边扩展,判断两边所存数组的值是否为0,结果测试到第15组数据是出错,后来才发现,忽略了数组之外的值,他们的值是随机的。

错误代码

#include<cstdio>
#include<cstring>
#include<iostream>using namespace std;const int MAXN = 1000;
int t[MAXN];int main()
{int n, a;while(scanf("%d%d",&n, &a)!=EOF){int cnt = 0;memset(t, 0, sizeof(t));for(int i =1; i <= n; i++)cin >> t[i];if(t[a]) cnt++;cout << cnt <<endl;for(int i = 1; i <= n; i++){if(t[a-i] >= 1&&t[a+i] == 1) {  //******错误点 cnt+=2;cout << cnt;}else if(a-i <= 0&&a+i <= n){if(t[a+i]) cnt++;cout << cnt ;}else if(a-i >= 1&&a+i > n){if(t[a-i]) cnt++;cout << cnt ;}printf(" %d\n",cnt);}}
}

将错误的地方改正

#include<cstdio>
#include<cstring>
#include<iostream>using namespace std;const int MAXN = 1000;
int t[MAXN];int main()
{int n, a;while(scanf("%d%d",&n, &a)!=EOF){int cnt = 0;//memset(t, 0, sizeof(t));for(int i =1; i <= n; i++)cin >> t[i];if(t[a]) cnt++;for(int i = 1; i <= n; ++i){if(a-i > 0&&a+i <= n) {  //******改正错误点 if(t[a-i] == 1&&t[a+i] == 1)cnt+=2;   }else if(a-i <= 0&&a+i <= n){if(t[a+i])cnt++;}   else if(a-i > 0&&a+i > n){if(t[a-i])cnt++;    }            }cout << cnt <<endl;}
}

Bear and Finding Criminals (模拟)相关推荐

  1. D - Bear and Finding Criminals

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

  2. Bear and Finding Criminals

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

  3. CF - 791A. Bear and Big Brother - 模拟

    1.题目描述: A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes inp ...

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

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

  5. 签到 2016.6.9

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

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

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

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

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

  8. *【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)

    题干: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections a ...

  9. jzoj5990. 【北大2019冬令营模拟2019.1.6】Bear (状压dp)

    题面 题解 我永远讨厌dp.jpg 搞了一个下午优化复杂度最后发现只要有一个小trick就可以A了→_→.全场都插头dp就我一个状压跑得贼慢-- 不难发现我们可以状压,对于每一行,用状态\(S\)表示 ...

最新文章

  1. R语言诊断试验数据处理与ROC分析实战案例:联合诊断ROC
  2. HDU 2022 海选女主角
  3. 【SSM框架系列】Spring IoC(控制反转) DI(依赖注入)注解开发
  4. C++字符串详解(二)访问与拼接
  5. mysql 分段执行_面试官问你MySQL的优化,看这篇文章就够了
  6. sklearn中模型的选择和各个模型的比较
  7. 【转】国密加密算法SM系列的C#实现方法
  8. 软考网络工程师学习笔记6-无线通信网
  9. Arrays.asList()的坑
  10. java dao修改语句_一个通用的DAO模型实现增删改查
  11. cisco 增强型内部网关路由协议EIGRP笔记
  12. python:threading.Thread类的使用详解
  13. mongoose 常用数据库操作 更新
  14. matplotlib绘制李萨如图(四) 利用交互模式动态3D李萨如图
  15. 记录一次iPhone5s的iCloud bypass经历
  16. c#语言开发app,C#开发Android App--03--创建第一个app--Hello World
  17. IT软件技术人员的职位路线(从程序员到技术总监) - 部门管理经验谈
  18. LTspice中 Voltage Controlled Switches的使用方法
  19. IOS面试攻略(1.0)
  20. restful 验证码平台请求验证

热门文章

  1. deep learning 作業 2.2
  2. 百度富文本编辑器UEditor安装配置全过程
  3. docker操作运行一步一步来
  4. 高等应用数学问题的matlab求解汇总
  5. ExtJS grid简单应用之 展示JSON数据
  6. 使用Silverlight3中的DataPager实现服务器端分页
  7. stdarg.h的库函数用法小结
  8. 【Python学习系列十】Python机器学习库scikit-learn实现Decision Trees案例
  9. Hive时间是String格式截取字串和转换数据类型小贴士
  10. vc采集网页内所有元素(不指定具体table/form/frame)