• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

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
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

链接:http://codeforces.com/contest/680/problem/B
这题也是水题,直接看底下的NOTE,更容易懂。
#include<bits/stdc++.h>

using namespace std;

#define SI(N) scanf("%d",&(N))

int main()
{
    int a[105]={0};
    int n,in;
    cin>>n>>in;
    for (int i=1;i<=n;i++)
    {
        SI(a[i]);
    }
    int ans=0;
    int l=in-1,r=in+1;
    while(l>=1&&r<=n)
    {
        if (a[l]==1&&a[r]==1)
        {
            ans+=2;
        }
        l--,r++;
    }
    if (l==0)
    {
        for (int i=r;i<=n;i++)
        {
            if (a[i]==1)
                ans++;
        }
    }
    if (r==n+1)
    {
        for (int i=l;i>=0;i--)
        {
            if (a[i]==1)
                ans++;
        }
    }
    if (a[in]==1)
        ans++;
    printf("%d\n",ans);
    return 0;
}
posted @ 2016-06-11 12:04  s1124yy  阅读(340)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3