标签:
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1161 Accepted Submission(s): 59
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<ctype.h> #include<algorithm> #include<cmath> #include<set> using namespace std; const int maxn=1000100; const int HM=100100; int n,K; int a[maxn]; long long d[maxn]; struct Hash { long long date; Hash *next; };Hash h[HM]; void insert(long long date,Hash *h) { int t=abs(date)%HM; Hash *pre=&h[t],*p=pre->next; while(p!=NULL){ if(p->date=date) return; pre=p; p=p->next; } p=(Hash*)malloc(sizeof(Hash)); p->date=date;p->next=NULL; pre->next=p; } bool find(long long date,Hash *h) { int t=abs(date)%HM; Hash *pre=&h[t],*p=pre->next; while(p!=NULL){ if(p->date==date) return true; pre=p; p=p->next; } return false; } inline int read() { char c=getchar(); while(c!=‘-‘&&!isdigit(c)) c=getchar(); int f=0,tag=1; if(c==‘-‘){ tag=-1; f=getchar()-‘0‘; } else f=c-‘0‘; while(isdigit(c=getchar())) f=f*10+c-‘0‘; return f*tag; } int main() { int T=read(); int tag=1; while(T--){ n=read();K=read(); d[0]=0; for(int i=1;i<=n;i++){ a[i]=read(); if(i&1) d[i]=d[i-1]+a[i]; else d[i]=d[i-1]-a[i]; } for(int i=0;i<HM;i++) h[i].next=NULL; bool flag=0; for(int i=n;i>=0;i--){ insert(d[i],h); if(i&1){ if(find(d[i]-K,h)) flag=1; } else if(find(d[i]+K,h)) flag=1; if(flag) break; } printf("Case #%d: ",tag++); if(flag) printf("Yes.\n"); else printf("No.\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/--560/p/4332548.html