| ||||||||||
| 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:谢谢.能看看下面的代码为什么错了吗? Posted by:MasterLuo at 2008-07-14 13:59:22 if(a[j].x>max.x && a[j].y>max.y && !used[j])
应该是if(a[j].x>=max.x && a[j].y>=max.y && !used[j])
少了两个等号
> #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