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 ...
随机推荐
- DataTable和DataRow利用反射直接转换为Model对象的扩展方法类
DataTable和DataRow利用反射直接转换为Model对象的扩展方法类 /// <summary> /// 类 说 明:给DataTable和DataRow扩展方法,直接转换为 ...
- Android 大众点评的接入
这里介绍的是大众点评的团购中的一个接口.就是全部团购信息,其它的接口的实现是大同小异的. 首先,登录大众点评的开发平台->大众点评 . 然后获取到自己的应用的appkey和secret.这个是 ...
- C#除法精度
string.empty()NULL 首先要安装虚拟机工具VMWare Tool这样鼠标进出使用也方便. 1.虚拟机和主机之间在安装了VMWare Tool之后可以实现剪贴板的共享,即可以复制粘贴.但 ...
- mysql 找出外键等约束
找出employee表的所有外键约束 select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_C ...
- cocos2d0基础篇笔记二
1.菜单的使用: CCMenuItemimage*image=CCMenuItemImage*create("xxx.png", "xxx,png", &quo ...
- 使用EA生成多层次的代码框架
最近工作期间发现了一个非常棒的UML软件[Enterprise Architect UML 建模工具]简称EA,在该软件上绘制框架层面的类之间关系后,可以自动生成相关语言的代码. EA上目前支持的语言 ...
- Android版App的控件元素定位
前言 如何获取页面上各控件元素,无论是Web自动化还是App自动化,此步骤都是非常关键的! Web页面的控件元素可通过开发者选项(Chrome浏览器的F12)来协助定位,App端也是有相应的工具来协助 ...
- OpenKM安装(CentOS6)
OpenKM全称是Open Knowledge Management,是一个DMS(文档管理系统).本文介绍如何在CentOS下安装它.本文的安装程序和资料全部来自OpenKM官网:http://ww ...
- Recurrent neural networks are very powerful, because they combine two properties
https://www.cs.toronto.edu/~hinton/csc2535/notes/lec10new.pdf Distributed hidden state that allows t ...
- tomcat安装后问题解决
tomcat安装后问题解决 (1)tomcat无法正常启动的原因分析 JAVA_HOME 配置错误,或者没有配置 如果你的机器已经占有了8080 端口,则无法启动, 解决方法 (1) 你可以808 ...