题解 P11796 【MX-X9-T0】『GROI-R3』NaiLong

· · 题解

盗图

这太有生活了~

定义一个标记数组,输入一次处理一次,如果这个人被知道了就改变,否则不变,然后按照要求输出即可,具体看代码

挺水的

注意小心数组访问越界或者出现负数下标

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=105;
int a[maxn];
int n,k;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
signed main ()
{
    n=read();
    k=read();
    for(int i=1;i<=n;i++)
    {
        int x;
        x=read();
        if(x==0)
        {
            a[i+1]++;
        }
        if(x==1)
        {
            a[i-1]++;
        }
    }
    if(a[k]!=0)
    {
        cout<<"Yes"<<"\n";
    }
    else
    {
        cout<<"No"<<"\n"; 
    }
    return 0;
}