您的位置:首页 > 其它

【HDU5183】Negative and Positive (NP)

2015-03-08 19:16 260 查看
传送门: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: