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 |
什么不说贴代码!#include <stdio.h> #include <stdlib.h> #include <string.h> #define M 5000+10 typedef struct stick { int l; int w; }sticks; sticks s[M]; int flag[M]; int cmp(const void *_a,const void *_b) { sticks *a=(sticks*)_a; sticks *b=(sticks*)_b; if(a->l==b->l) return a->w-b->w; return a->l-b->l; } int main() { int cases,i,j,ans,n,k; scanf("%d",&cases); while(cases--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%d %d",&s[i].l,&s[i].w); qsort(s,n,sizeof(sticks),cmp); ans=0; memset(flag,0,sizeof(flag)); for(i=0;i<n;i++) { if(flag[i]) continue; k=i; for(j=i+1;j<n;j++) if(s[k].w<=s[j].w&&!flag[j]) { k=j; flag[j]=1; } ans++; } printf("%d\n",ans); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator