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

虽然跟很多人的贪心不太一样,但是我认为这个算法还是没错的吧??!

Posted by Basara at 2006-08-11 12:49:14 on Problem 1065
In Reply To:Re:代码如下: Posted by:Basara at 2006-08-10 22:31:24
> #include <iostream>
> using namespace std;
> 
> typedef struct {
> 	int len;
> 	int wid;
> }item;
> item  wood[5000];
> item  queue[5000];
> 
> int compare(const void *a, const void *b){
>  return (*((item *)b)).len +(*((item *)b)).wid -(*((item *)a)).len -(*((item *)a)).wid;	
> }
> int main(){
> 	//freopen("test.txt","r",stdin);
>     int kase,i,j,n,queuelen,find;
>     scanf("%d",&kase);
> 	while(kase--){
> 		scanf("%d",&n);
> 		for(i=0;i<n;i++){
> 			scanf("%d%d",&wood[i].len,&wood[i].wid);
> 		}
> 		qsort(wood,n,sizeof(item),compare);  //sort decreasely by sum of len and wid		
>         queuelen=0;
> 		queue[0]=wood[0];
> 		for(i=1;i<n;i++){
> 			find=0;
> 			for(j=0;j<=queuelen;j++){
> 				if(wood[i].len<=queue[j].len && wood[i].wid<=queue[j].wid){
> 					find=1;
> 					queue[j]=wood[i];
> 					break;
> 				}				
> 			}
> 			if(!find) {
> 					queue[++queuelen]=wood[i];
> 				}
> 		}		
>         printf("%d\n",queuelen+1);
> 	}
> 	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