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

哪位大牛给看下哪错了,一直是WA!谢谢!

Posted by 194 at 2006-08-22 16:48:49 on Problem 2726
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef struct Node
{
	int D;
	int C;

}HotelNode;

int main()
{
	int cmp( const void *a , const void *b );
	HotelNode Hotel[10000];
	int t,i,n,p;
	cin>>t;
	while(t)
	{
		for(i=0;i<t;i++)
		{
			cin>>Hotel[i].D>>Hotel[i].C;
		}
        qsort(Hotel,i,sizeof(Hotel[0]),cmp); 
		p=0;
		i=0;
		n=0;
        while(i<t)
		{
			if(i+1<t&&Hotel[i].D==Hotel[i+1].D&&Hotel[i+1].C<Hotel[p].C)
			{
				p=i+1;
				n++;
			}
			else if(Hotel[i].C<Hotel[p].C)
			{
				n++;
				p=i;
			}
			i++;		
		}
		cout<<n<<endl;
		cin>>t;
	}
	return 1;
}

int cmp( const void *a , const void *b ) 
{ 
  struct Node *c = (Node *)a; 
  struct Node *d = (Node *)b; 
  if(c->D != d->D) return c->D - d->D; 
  else return d->C - c->C; 
} 


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