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 luozhongzhu at 2009-07-16 11:26:51 on Problem 1083
In Reply To:这样贪心不知哪里错了,呜呜~大家帮忙看下 Posted by:haoren at 2009-06-22 10:20:11
> #include <iostream>
> 
> using namespace std;
> 
> int n , vis[410];
> 
> struct node
> {
> 	int b , e;
> }ran[210];
> 
> int cmp(const void *x , const void *y)
> {
> 	struct node * c = (node*)x ;
> 	struct node * d = (node*)y;
> 	if(c->b != d->b)
> 		return c->b - d->b;
> 	return c->e - d->e;
> }
> 
> int main()
> {
> 	int T;
> 	scanf("%d" , &T);
> 
> 	while(T --)
> 	{
> 		scanf("%d" , &n);
> 		
> 		int i , j;
> 		for(i = 0 ; i < n ; i ++){
> 			scanf("%d%d" , &ran[i].b , &ran[i].e);
> 			if(ran[i].b > ran[i].e){
> 				int temp = ran[i].b;
> 				ran[i].b = ran[i].e;
> 				ran[i].e = temp;
> 			}
> 			if(ran[i].b%2 == 0)
> 				ran[i].b --;
> 			if(ran[i].e%2 == 1)
> 				ran[i].e ++;
> 		}
> 
> 		memset(vis , 0 , sizeof(vis));
> 		qsort(ran, n , sizeof(ran[0]) , cmp);
> 
> 		int res = 0;
> 
> 		for(i = 0 ; i < n ; i ++){
> 			if(vis[i] == 0){
> 				res ++;
> 				int t = ran[i].e;
> 				vis[i] = 1;
> 				for(j = i + 1; j < n ; j ++){
> 					if(ran[j].b > t){
> 						vis[j] = 1;
> 						t = ran[j].e;
> 					}
> 				}
> 			}
> 		}
> 		printf("%d\n" , 10*res);
> 	}
> 
> 	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