Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
强大的printf,scanf ,用cin,cout居然TLE..用printf,scanf 2800ms飘过去了(附代码)#include<iostream> using namespace std; struct snow{ int arm[6]; }a[100000]; int int_cmp(const void * a,const void *b) { return *((int *)a)-*((int *)b); } int b_cmp(const void * a,const void * b) { snow* s1=(snow*)a; snow* s2=(snow*)b; for(int i=0;i<5;i++){ if(s1->arm[i]!=s2->arm[i]) return s1->arm[i]-s2->arm[i]; } return s1->arm[5]-s2->arm[5]; } int bb_cmp(const void * a,const void * b) { int* s1=(int*)a; snow* s2=(snow*)b; for(int i=0;i<5;i++){ if(s1[i]!=s2->arm[i]) return s1[i]-s2->arm[i]; } return s1[5]-s2->arm[5]; } int main() { int n,i,j; cin>>n; for(i=0;i<n;i++) for(j=0;j<6;j++) scanf("%d",&a[i].arm[j]); for(i=0;i<n;i++) qsort(a[i].arm,6,sizeof(int),int_cmp); qsort(a,n,sizeof(snow),b_cmp); bool flag=false; for(i=0;i<n;i++){ snow* p; int *tmp=a[i].arm; p=(snow*)bsearch(tmp,a+i+1,n-i-1,sizeof(snow),bb_cmp); if(p){ flag=true; break; } } if(flag) printf("Twin snowflakes found.\n"); else printf("No two snowflakes are alike.\n"); system("pause"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator