Codeforces-Round-#356-(Div.-2)-Bear-and-Finding-Criminals
2016-06-09 16:22
507 查看
Bear and Finding Criminals
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 citya.
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
output
input
output
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.
题意:告诉你n个城市上的罪犯个数,以及警察所在位置,警察能够知道距离他附近i单位的城市上是否有罪犯,但不知道他在哪个城市,要你求他最多能抓到的罪犯个数。
题目链接:Bear and Finding Criminals
解题思路:
分2种情况。
一.与位置p相距i单位的左边,右边城市都有罪犯,那么随便跑哪个城市都能抓到罪犯,且两个都能抓到。
二.与位置p相距i单位的左边(右边)没有城市,但是对称的右边(左边)有城市,且城市里面有罪犯,也就是有罪犯的城市唯一,那么这个罪犯就一定能被抓到。
代码:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 citya.
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.
题意:告诉你n个城市上的罪犯个数,以及警察所在位置,警察能够知道距离他附近i单位的城市上是否有罪犯,但不知道他在哪个城市,要你求他最多能抓到的罪犯个数。
题目链接:Bear and Finding Criminals
解题思路:
分2种情况。
一.与位置p相距i单位的左边,右边城市都有罪犯,那么随便跑哪个城市都能抓到罪犯,且两个都能抓到。
二.与位置p相距i单位的左边(右边)没有城市,但是对称的右边(左边)有城市,且城市里面有罪犯,也就是有罪犯的城市唯一,那么这个罪犯就一定能被抓到。
代码:
相关文章推荐
- python的GUI编程--wxpython学习(二)--基本控件和事件
- random forest
- c语言 程序 快速排序
- IO流-Properties
- 递归
- 《用tcp/ip进行网际互联》第6章 网际协议:无连接数据报交付
- hdu 最短路径
- sqlplus执行SQL文件
- Compare Version Numbers
- atom无法安装插件的解决方法之一
- SSH开发问题——attempt to create saveOrUpdate event with null entity
- Dns & IPAddress
- SQL 2008 视频总结(三)
- LeetCode-37.Sudoku Solver
- java.io.File
- Codeforces Round #328 (Div. 2) D. Super M
- Lightoj 1005 Rooks(DP)
- 团体程序设计天梯赛 L2-009. 抢红包
- 日历管理系统
- CentOS进入单用户模式更改密码