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 |
Re:熟悉编译器的过来看一下,stable_sort换成sort就RE了In Reply To:熟悉编译器的过来看一下,stable_sort换成sort就RE了 Posted by:Darren at 2008-04-01 15:44:25 > 参照例程写的,例程是用cstdlib里的qsort > 我用sort一遇到大数据,例如第3个数据n=99就RE了,本地也一样 > > #include<iostream> > #include<vector> > #include<cstring> > #include<queue> > #include<stack> > #include<map> > #include<set> > #include<algorithm> > #include<numeric> > #include<cstdio> > #include<cmath> > #include<cctype> > using namespace std; > #define FOR(i,n) for (int i=0;i<n;i++) > #define FORI(i,s) for (int i=0;i<s.size();i++) > #define BEND(x) (x).begin(),(x).end() > #define FORALL(it,st) for(typeof(st.begin())it=st.begin();it!=st.end();it++) > const int MAXN=1024; > char a[MAXN*MAXN]; > int p[MAXN*MAXN]; > int c[MAXN]; > char *prev; > bool Cmp(int x,int y) > { > return strcmp(a+x,a+y)<=0; > } > int common(int x,int y) > { > int i; > for(i=0;i<MAXN;i++) > if(a[x+i]!=a[y+i]||!a[x+i]||!a[y+i]) > return i; > } > int main() > { > int n,i,j,k,s,best,l,r,done=0; > while(scanf("%d",&n)&&n) > { > if(done++) > printf("\n"); > k=0; > for(i=s=0;i<n;i++,s+=MAXN) > { > scanf("%s",a+s); > for(j=s;a[j];j++) > p[k++]=j; > } > stable_sort(p,p+k,Cmp); ///就是这里导致RE的,换成sort的话 > l=r=best=s=0; > memset(c,0,sizeof(c)); > while(r<k) > { > while(s<=n/2&&r<k) > if(!c[p[r++]/MAXN]++) > s++; > while(s>n/2&&l<r) > if(!--c[p[l++]/MAXN]) > s--; > if(l) > best>?=common(p[l-1],p[r-1]); > } > if(best==0) > { > printf("?\n"); > continue; > } > l=r=s=0; > memset(c,0,sizeof(c)); > prev=""; > while(r<k) > { > while(s<=n/2&&r<k) > if(!c[p[r++]/MAXN]++) > s++; > while(s>n/2&&l<r) > if(!--c[p[l++]/MAXN]) > s--; > if(common(p[l-1],p[r-1])==best) > if(strncmp(prev,a+p[l-1],best)) > { > prev=a+p[l-1]; > for(j=0;j<best;j++) > printf("%c",*(prev+j)); > printf("\n"); > } > } > } > return 0; > } cmp函数里的<=应改为< Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator