Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:谢谢.能看看下面的代码为什么错了吗?

Posted by TerranRush at 2008-09-01 22:28:32 on Problem 3636
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator