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:谢谢.能看看下面的代码为什么错了吗?In Reply To:Re: How to greedy? first sort?buct how to do after it? Posted by:matrixlc at 2008-07-13 19:57:29 #include <iostream> #include <algorithm> using namespace std; int t, n, m; struct Node { int x, y; }a[20008]; bool used[20008]; bool operator<(Node min, Node max) { if(min.x<max.x ||(min.x==max.x && min.y<max.y)) return true; return false; } int main() { scanf("%d", &t); while(t--) { int min=0; scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d%d", &a[i].x, &a[i].y); sort(a, a+n); for(int i=0; i<n; i++) used[i]=false; Node max; for(int i=0; i<n; i++) { if(!used[i]) { min++; used[i]=true; max=a[i]; for(int j=i+1; j<n; j++) { if(a[j].x>max.x && a[j].y>max.y && !used[j]) { max=a[j]; used[j]=true; } } } } printf("%d\n", min); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator