• D


    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

    Input
    6 3
    1 1 1 0 1 0
    Output
    3
    Input
    5 2
    0 0 0 1 0
    Output
    1

    题意:共有n座城市,Limak在第a座城市,每做城市的距离即序列号相减的绝对值。米格城市最多有一名罪犯,BCD可以告诉Limak在某个距离处有多少罪犯,如果Limak确定罪犯在哪个城市,就可以抓到他,求他可以抓住多少罪犯。

    如:

    1 1 1 0 1 0   Limak在第三位,则BCD可知距离为1处有1名罪犯,则Limak不能确定在哪个城市故无法抓到;距离为2处有两名,则确定每个城市必有一名,故抓到两名;距离为3处有一名,因为距离为3 的城市只有一座,也能确定,故抓住一名。

    附AC代码:

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 int n,m;
     8 int a[110];
     9 
    10 int main(){
    11     while(cin>>n>>m){
    12         int sum=0;
    13         memset(a,0,sizeof(a));
    14         for(int i=1;i<=n;i++){
    15             cin>>a[i];
    16         }
    17         for(int i=0;i<n;i++){
    18             if(m-i<1&&m+i<=n){
    19                 if(a[m+i]==1){
    20                     sum++;
    21                     continue;
    22                 }
    23             }
    24             if(m+i>n&&m-i>=1){
    25                 if(a[m-i]==1){
    26                     sum++;
    27                     continue;
    28                 }
    29             }
    30             if(a[m-i]==1&&a[m+i]==1){
    31                 if(m-i==m+i){
    32                     sum++;
    33                     continue;
    34                 }
    35                 else{
    36                     sum+=2;
    37                     continue;
    38                 }
    39                 
    40             }
    41         }
    42         cout<<sum<<endl;
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    让WPF的Popup不总置顶的解决方案
    virtio 驱动的数据结构理解
    关于Linux下面msyql安装后并未设置初始密码,但是登录报错“Access denied for user 'root'@'localhost' (using password: NO)”的解决方案
    gulp初涉
    前后端分离--构建前端Mock Server--windows部署rap
    一些css小用法总结(持续更新~)
    js原生封装自定义滚动条
    ie下面兼容性问题的一些总结
    关于html水平垂直居中的一些总结吧
    C# 正则表达式匹配string字符串中的时间串(yyyyMMdd)
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5659211.html
Copyright © 2020-2023  润新知