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:一直是WA,谁能帮我看一下In Reply To:一直是WA,谁能帮我看一下 Posted by:xuezhimeng at 2006-08-07 11:10:14 > 源代码: > > #include<stdio.h> > #include<algorithm> > using namespace std; > > typedef struct > { > int len; > int w; > }stick; > > > bool cmp(stick x,stick y) > { > if(x.len<y.len) return 1; //排序这里,如果我改成if(x.len<=y.len)就超时,不改就WA > else return 0; > } > > int main() > { > int t; > int i,j,k; > scanf("%d",&t); > for(i=0;i<t;i++) > { > stick *a; > int n; > > scanf("%d",&n); > a = new stick [n]; > for(j=0;j<n;j++) > { > scanf("%d %d",&a[j].len,&a[j].w); > } > sort(a,a+n,cmp); > // QSort(a,0,n-1); > > > int *flag; > flag = new int[n]; > for(j =0;j<n;j++) > flag[j]=0; > int sum= 0 ; > > for(j = 0;j<n;j++) > { > for(k = j+1;k<n;k++) > { > if(flag[k] == 0 && a[k].w >= a[j].w) > { > flag[k] = 1; > sum++; > } > } > } > > printf("%d\n",n-sum); > } > return 1; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator