D - Bear and Finding Criminals
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
Input6 3
1 1 1 0 1 0Output3Input5 2
0 0 0 1 0Output1
题意:共有n座城市,Limak在第a座城市,每做城市的距离即序列号相减的绝对值。米格城市最多有一名罪犯,BCD可以告诉Limak在某个距离处有多少罪犯,如果Limak确定罪犯在哪个城市,就可以抓到他,求他可以抓住多少罪犯。
如:
1 1 1 0 1 0 Limak在第三位,则BCD可知距离为1处有1名罪犯,则Limak不能确定在哪个城市故无法抓到;距离为2处有两名,则确定每个城市必有一名,故抓到两名;距离为3处有一名,因为距离为3 的城市只有一座,也能确定,故抓住一名。
附AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; int n,m;
int a[]; int main(){
while(cin>>n>>m){
int sum=;
memset(a,,sizeof(a));
for(int i=;i<=n;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
if(m-i<&&m+i<=n){
if(a[m+i]==){
sum++;
continue;
}
}
if(m+i>n&&m-i>=){
if(a[m-i]==){
sum++;
continue;
}
}
if(a[m-i]==&&a[m+i]==){
if(m-i==m+i){
sum++;
continue;
}
else{
sum+=;
continue;
} }
}
cout<<sum<<endl;
}
return ;
}
D - Bear and Finding Criminals的更多相关文章
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- codeforces 680B B. Bear and Finding Criminals(水题)
题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...
- Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题
B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description Ther ...
- Codeforces Round #356 (Div. 2)-B
B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in B ...
- Codeforces Round #356 (Div. 2)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 每日英语:Why Are Items Pricier in China?
In China, consumers pay nearly $1 more for a latte at Starbucks than their U.S. counterparts. A Cadi ...
- 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 ...
- Codeforces CF#628 Education 8 F. Bear and Fair Set
F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces CF#628 Education 8 C. Bear and String Distance
C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- 利用CH341A编程器刷新BIOS,恢复BIOS,妈妈再也不用担心BIOS刷坏了
前几天,修电脑主析就捣鼓刷BIOS,结果刷完黑屏开不了机,立刻意识到完了,BIOS刷错了.就从网上查资料,各种方法试了个遍,什么用处都没有.终于功夫不负有心人,找到了编码器,知道了怎么用.下面看看具体 ...
- 隐私问题成O2O绊脚石,加强行业监管迫在眉睫
这年头,O2O的发展越来越给力了.因为O2O能充分结合互联网经济的线上优势和传统经济的线下优势,因此,传统商户纷纷借助O2O来开展业务,取得了不俗的成绩.只是,在移动互联网越来越"开 ...
- Html.DropDownListFor的选项值为字符型问题
我快要疯了.asp.net mvc的这个DropDownListFor,无论在服务器端如何设置,设置哪个值被选中,结果到了页面输出,选中值根本没有被选中,没有任何一个值被选中,下拉框只冷冰冰地显示一个 ...
- 组件的详细说明和生命周期ComponentSpecs and Lifecycle
render ReactComponent render() render() 方法是必须的. 当调用的时候,会检测 this.props 和 this.state,返回一个单子级组件.该子级组件可以 ...
- RTP/RTCP学习笔记 -- RFC 3550
The MTU of RTP package payload is (IP) - (UDP) - = 1472 #define DEFAULT_MAX_PACKET_SIZE 1200 video ...
- MongoDB 倾向于将数据都放在一个 Collection 下吗?
不是这样的. Collection 的单个 doc 有大小上限,现在是 16MB,这就使得你不可能把所有东西都揉到一个 collection 里.而且如果 collection 结构过于复杂,既会影响 ...
- html5 canvas基本用法
通过对canvas的初步了解,经过几天的总结,吧canvas的基本用法总结如下:方便以后查阅 <!doctype html> <html> <head> <m ...
- 在win7系统下安装把Ubuntu17.04安装在另一个硬盘开机无法进入Ubuntu问题的一种解决办法。【转】
本文转载自:http://blog.csdn.net/u012879090/article/details/74937762 在win7系统下安装把Ubuntu17.04安装在另一个硬盘开机无法进入U ...
- 理解数学公式与numpy矩阵运算
1.矩阵的初始化 (1)创建一个 3*5的全0矩阵和全1矩阵 import numpy as np myzero = np.zeros([3,5]) print myzero myones = np. ...
- FFmpeg big changes. ffmpeg 接口的一些改变
Big changes have been made from FFmpeg 0.5.1… Refer to http://cekirdek.pardus.org.tr/~ismail/ffmpeg- ...