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 |
原题16组数据全都在自己的机器上过了,但在poj上。。。。郁闷了不用随机快排。。。。tle 用随机快排。。。。runtime error 实在是不知该如何过了,大牛们来帮帮忙啊。。。。以下是代码。。。 #include<iostream> #include<math.h> #include<cstdlib> #include<time.h> #include<stdlib.h> using namespace std; int a[1000000],e; void qsort(int l,int r) { long int i,j,mid; i=l; j=r; mid=a[l+rand()%(r-l+1)]; //mid=a[(l+r)/2]; do { while(a[i]<mid) i++; while(a[j]>mid) j--; if(i<=j) {e=a[i]; a[i]=a[j]; a[j]=e; i++; j--;} }while(i<=j); if(j>l) qsort(l,j); if(r>i) qsort(i,r); } int main() { //ofstream ofile; //ifstream ifile; long int n,i,j,save; char c; bool flag=true; srand((unsigned)time(NULL)); //ifile.open("E.2.dat",ios_base::binary); //ifile>>n; cin>>n; for(i=0;i<n;i++) { a[i]=0; for(j=0;j<7;) { save=0; //ifile>>c; cin>>c; if((c>='0'&&c<='9')||(c>='A'&&c<='Y'&&c!='Q')) { j++; if(c=='1') save=1; else if(c=='2'||c=='A'||c=='B'||c=='C') save=2; else if(c=='3'||c=='D'||c=='E'||c=='F') save=3; else if(c=='4'||c=='G'||c=='H'||c=='I') save=4; else if(c=='5'||c=='J'||c=='K'||c=='L') save=5; else if(c=='6'||c=='M'||c=='N'||c=='O') save=6; else if(c=='7'||c=='P'||c=='R'||c=='S') save=7; else if(c=='8'||c=='T'||c=='U'||c=='V') save=8; else if(c=='9'||c=='W'||c=='X'||c=='Y') save=9; a[i]+=save*(int)exp((7-j)*log(10)); } } } //ifile.close(); //ofile.open("out.dat",ios_base::out); qsort(0,n-1); save=1; j=0; for(i=1;i<n;i++) { if(a[i]==a[i-1]) save++; else { if(save>1) { flag=false; if(a[i-1]/10000==0) cout<<"000"; else if(a[i-1]/100000==0) cout<<"00"<<a[i-1]/10000; else if(a[i-1]/1000000==0) cout<<'0'<<a[i-1]/10000; else cout<<a[i-1]/10000; cout<<'-'; if(a[i-1]%10000==0) cout<<"0000"; else if((a[i-1]%10000)/10==0) cout<<"000"<<a[i-1]%10000; else if((a[i-1]%10000)/100==0) cout<<"00"<<a[i-1]%10000; else if((a[i-1]%10000)/1000==0) cout<<"0"<<a[i-1]%10000; else cout<<a[i-1]%10000; cout<<' '<<save<<endl; } save=1; } if(i==n-1&&save>1) { flag=false; if(a[i-1]/10000==0) cout<<"000"; else if(a[i-1]/100000==0) cout<<"00"<<a[i-1]/10000; else if(a[i-1]/1000000==0) cout<<'0'<<a[i-1]/10000; else cout<<a[i-1]/10000; cout<<'-'; if(a[i-1]%10000==0) cout<<"0000"; else if((a[i-1]%10000)/10==0) cout<<"000"<<a[i-1]%10000; else if((a[i-1]%10000)/100==0) cout<<"00"<<a[i-1]%10000; else if((a[i-1]%10000)/1000==0) cout<<"0"<<a[i-1]%10000; else cout<<a[i-1]%10000; cout<<' '<<save<<endl; } } if(flag) cout<<"No duplicates."; //ofile.close(); return(0); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator