Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题
B. Bear and Finding Criminals
题目连接:
http://www.codeforces.com/contest/680/problem/B
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
6 3
1 1 1 0 1 0
Sample Output
3
Hint
题意
有6个城市,有一个警察在a,有一个探测器,可以探测到距离他为i的地方有多少个歹徒。
现在给你每个城市的歹徒数量,最多为1
问你这个警察能够确认歹徒的所在的歹徒,一共有多少个
题解:
模拟一下就好了,如果左右都没有越界的话,那么必须左右都得有歹徒
否则就必须其中一边越界才行。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n,a,p[maxn];
int main()
{
scanf("%d%d",&n,&a);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
int ans = p[a];
for(int i=0,l=a-1,r=a+1;l>=1||r<=n;l--,r++){
if(l>=1&&r<=n){
if(p[l]&&p[r])ans+=2;
}
else if(l>=1)ans+=p[l];
else if(r<=n)ans+=p[r];
}
cout<<ans<<endl;
}
Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题的更多相关文章
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题
A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little be ...
- 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 Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题
A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...
随机推荐
- 使用pandas把mysql的数据导入MongoDB。
使用pandas把mysql的数据导入MongoDB. 首先说下我的需求,我需要把mysql的70万条数据导入到mongodb并去重, 同时在第二列加入一个url字段,字段的值和第三列的值一样,代码如 ...
- C#利用System.Net发送邮件
啥也不说了,直接上干货 using System.Net.Mail;using System.Net; //使用发送邮件的邮箱 var emailAcount = "826217795@qq ...
- nodejs 接收上传的图片
1.nodejs接收上传的图片主要是使用formidable模块,服务器是使用的express搭建. 引入formidable var formidable = require('./node_mod ...
- 纯css进度条,各种兼容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD&g ...
- 09 Command Documentation 命令文档
Command Documentation 命令文档 There is a suite of programs to build and process Go source code. Inste ...
- 使用Scrapy命令行工具【导出JSON文件】时编码设置
Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 使用scrapy命令行工具建立了爬虫项目(startproject),并使用s ...
- js数组基本操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtm ...
- eclipse中Maven项目jar问题
eclipse中Maven项目jar包下载下来了,不然我们import是时候根本导入不进来,网上的方法都试过了,Maven仓库也清空过后重新下载过了,都解决不了. 后来发现虽然jar包是下载下来了,可 ...
- Filebeat入门
一.安装filebeat 简介 Beats 是安装在服务器上的数据中转代理. Beats 可以将数据直接传输到 Elasticsearch 或传输到 Logstash . Beats 有多种类型,可以 ...
- JS实现点击图片,在浏览器中查看。
工作中遇到要实现点击图片查看的功能,从网上找了一段js代码,可以用. <img src="/pic/${pictureCertificate}" alt="凭证&q ...