【HDU5183】Negative and Positive (NP)

来源:互联网 发布:python 线程同步 编辑:程序博客网 时间:2024/05/18 01:18

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5183

#include <cstdio>#include <algorithm>#include <iostream>#include <cmath>#include <stdio.h>#include <set>using namespace std;typedef long long LL;set<LL>s;LL a[1000005];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-'0';        ch=getchar();    }    return x*f;}int main(){    int t;    int flag;    scanf("%d",&t);    int cnt=1;    while(t--)    {        int n;        LL k;        n=read();        k=read();        for(int i=1; i<=n; i++)        {            a[i]=read();            if(i%2==0)                a[i]=-a[i];        }        printf("Case #%d: ", cnt++);        for(int i=1; i<=n; i++)        {            a[i]+=a[i-1];        }        flag=1;        s.clear();        for(int i=n; i>=0&&flag; i--)        {            if(i%2==0)            {                if(s.find(a[i]+k)!=s.end())                    flag=0;            }            else            {                if(s.find(a[i]-k)!=s.end())                    flag=0;            }            s.insert(a[i]);        }        if(flag==0)           puts("Yes.");        else           puts("No.");    }    return 0;}


0 0
原创粉丝点击