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 <iostream> #include <cstdio> #include <algorithm> using namespace std; struct ss{ int x,y,z; }; int cmp(ss w,ss t) { if(w.x==t.x)return w.y<t.y; else return w.x<t.x; } int main() { int i,n,sum,k,flag,j; ss a[5005]; scanf("%d",&k); while (k--) { sum=0; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].y); a[i].z=0; } sort(a,a+n,cmp); flag=n; for(j=0;j<=n-1;j++) { if(a[j].z==0) { sum++; int ww=j; for (i=ww+1;i<=n-1;i++) { if(a[i].z==0&&a[i].y>=a[ww].y) { a[i].z=-1; ww=i; } } } } printf("%d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator