WOJ1133-Candies

KO loves candies. Most of all, he likes chocolate, strawberry and banana flavored ones. Now, he has N bags full of candies, each bag contains 
some candies of all three flavors. KO knows the number of candies of each flavor in each bag. He wants to put all chocolate ones into one bag, 
all strawberry ones into another bag and all banana ones into yet another bag. He has to move the candies one-by-one, because he always has to 
look at it to determine its flavor. Moving one candy from one bag into another takes 1 second Your task is to select the bag for each flavor, 
so that the total time required for KO to move all the candies into the selected bags would be minimal. Output the minimum total time. 

输入格式

There will be multiple test cases. For each test case, the first line contains a single integer N(3 <= N <= 10000) - the number of bags. Each
of the following N lines consists of three numbers c, s, b (0 <= c, s, b <= 30000) each? the number of chocolates, strawberry and banana
candies of the i-th bag. The bags are numbered from 1 to N in the order in which they appear in the input.

输出格式

For each test case, output an integer which is the minimal total time to move all the candies to the selected bags.

样例输入

5
10 10 10
40 39 40
10 20 30
30 20 10
1 2 27

把每个属性前3大的取出来去重,然后从其中(最多9个)暴力选3个出来取max。

#include<stdio.h>
int n,sum,candy[10000][3],ko[3][3];
void findmax(int x,int y){
	int i,max=0;
	for(i=0;i<n;i++){
		if(y==1){
			if(i==ko[x][0])
			continue;
		}
		else if(y==2){
			if(i==ko[x][0]||i==ko[x][1])
			continue;
		}
		if(candy[i][x]>max){
			max=candy[i][x];
			ko[x][y]=i;
		}
	}
}
int main(){
	int i,j,k,min,temp;
	while(scanf("%d",&n)==1){
		sum=0;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&candy[i][0],&candy[i][1],&candy[i][2]);
			sum=sum+candy[i][0]+candy[i][1]+candy[i][2];
		}
		for(i=0;i<3;i++)
		for(j=0;j<3;j++)
		findmax(i,j);	
		min=0x7fffffff;
		for(i=0;i<3;i++)
		for(j=0;j<3;j++)
		for(k=0;k<3;k++){
			if(ko[0][i]==ko[1][j]||ko[0][i]==ko[2][k]||ko[1][j]==ko[2][k])
			continue;
			temp=sum-candy[ko[0][i]][0]-candy[ko[1][j]][1]-candy[ko[2][k]][2];
			if(temp<min)
			min=temp; 
		}
		printf("%d\n",min);
	}
	return 0;
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值