标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 613 Accepted Submission(s): 326
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 using namespace std; 7 struct node 8 { 9 int num,f,s,c; 10 }; 11 node city[107]; 12 int ans[107]; 13 int n; 14 bool cmp(node n1,node n2) 15 { 16 if(n1.c!=n2.c) return n1.c>n2.c; 17 if(n1.s!=n2.s) return n1.s<n2.s; 18 return n1.num<n2.num; 19 } 20 int main() 21 { 22 // freopen("in.txt","r",stdin); 23 while(~scanf("%d",&n)){ 24 memset(city,0,sizeof(city)); 25 for(int i=0;i<n;i++) 26 { 27 city[i].num=i; 28 scanf("%d%d",&city[i].f,&city[i].s); 29 city[i].c=city[i].f-city[i].s; 30 } 31 sort(city,city+n,cmp); 32 for(int i=0;i<n;i++) 33 { 34 ans[city[i].num]=i; 35 } 36 bool ff=1; 37 for(int i=0;i<n;i++) 38 { 39 if(ff) printf("%d",city[i].num),ff=0; 40 else { 41 printf(" %d",city[i].num); 42 } 43 } 44 printf("\n"); 45 } 46 return 0; 47 }
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2453 Accepted Submission(s): 605
1 #include<iostream> 2 #include<cstdio> 3 #include<set> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<vector> 8 using namespace std; 9 const int mod=1000007; 10 const int maxn=1000010; 11 const int add=1000000000; 12 long long sum1[maxn],sum2[maxn]; 13 int n,k; 14 struct HASHMAP 15 { 16 int head[maxn],next[maxn],sum; 17 long long value[maxn]; 18 void init() 19 { 20 memset(head,-1,sizeof(head)); 21 sum=0; 22 } 23 bool check(long long val) 24 { 25 int h=(val%mod+mod)%mod; 26 for(int i=head[h];~i;i=next[i]){ 27 if(value[i]==val) return 1; 28 } 29 return 0; 30 } 31 bool insert(long long val) 32 { 33 int h=(val%mod+mod)%mod; 34 for(int i=head[h];~i;i=next[i]) 35 if(value[i]==val) return 1; 36 value[sum]=val; 37 next[sum]=head[h]; 38 head[h]=sum++; 39 return 0; 40 } 41 }H1,H2; 42 int main() 43 { 44 // freopen("in.txt","r",stdin); 45 int t; 46 scanf("%d",&t); 47 int value; 48 int cnt=1; 49 while(t--){ 50 H1.init();H2.init(); 51 memset(sum1,0,sizeof(sum1)); 52 int sign1=1,sign2=1; 53 scanf("%d%d",&n,&k); 54 bool ans=0; 55 int tt; 56 H1.insert(0); 57 for(int i=1;i<=n;i++) 58 { 59 scanf("%d",&value); 60 if(ans==1) continue; 61 if(sign1==1) sum1[i]=sum1[i-1]+value; 62 else sum1[i]=sum1[i-1]-value; 63 if(i%2==0) H1.insert(sum1[i]); 64 if(H1.check(sum1[i]-k)) ans=1; 65 sum2[i]=-sum1[i]; 66 if(i%2) H2.insert(sum2[i]); 67 if(H2.check(sum2[i]-k)) ans=1; 68 sign1*=-1; 69 } 70 if(ans) printf("Case #%d: Yes.\n",cnt++); 71 else printf("Case #%d: No.\n",cnt++); 72 } 73 return 0; 74 }
标签:
原文地址:http://www.cnblogs.com/codeyuan/p/4338597.html