WOJ1007-Feeding Animals(I)

7:13 On the same day Noah, with Shem, Ham, and Japheth, his sons, and his wife and his sons' wives, went into the ark;
7:14 And with them, every sort of beast and cattle, and every sort of thing which goes on the earth, and every sort of bird.
7:15 They went with Noah into the ark, two and two of all flesh in which is the breath of life.
7:16 Male and female of all flesh went in, as God had said, and the ark was shut by the Lord.
Once abroad,many have suggested that Noah's problems really began, with only 8 people to feed and water, to provide fresh air and sanitation
for the huge menagerie of animals.Given a list of how much time it takes for one person to feed an animal, you must find the minimum account of
total time needed to feed all of the animals.The time given from any person to feed any animal will not exceed 10000.

输入格式

【The input contains several test cases.】 (see more in hint). For each test case,the first line contains the number of animals, n (1 <= n <= 10000).
The following 8 lines contain the 8 * n time matrix, where each element shows the time for one person to feed an animal.
Elements in each line is separated by a single space.

输出格式

For each test case,output a single line containing an integer that is the sum of the minimum time needed to feed all of the animals.

样例输入

3
10 20 30
20 15 20
2 10 8
4 8 30
3 8 10
50 70 10
20 30 40
10 30 20
2
10 20
20 15
2 10
4 8
3 8
50 70
20 30
10 30

样例输出

18
10

#include <stdio.h>
#define MAX 10000
int main() {
	int i,j,rop;
	int time[8][MAX],tmp[MAX],data[100];
	int n,min;
	rop=0;

	while(scanf("%d",&n) == 1) {
		min = 0;
		for(i=0; i<8; i++)
			for(j=0; j<n; j++)
				scanf("%d",&time[i][j]);
		for(j=0; j<n; j++)
			tmp[j] = time[0][j];
		for(j=0; j<n; j++) {
			for(i=0; i<8; i++) {
				tmp[j] = (tmp[j] < time[i][j])? tmp[j]:time[i][j];
			}
			min = min + tmp[j] ;
		}
		data[rop]=min;
		rop++;
	}
	for(i=0; i<rop; i++)
		printf("%d\n",data[i]);
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值