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;
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 12:05
俺不中了,BOSS遇到了一个hr,我觉得我咨询的问题都很正常吧,然后直接就被拒绝了???
恶龙战士:你问的太多了,要不就整理成一段话直接问他,一个一个问不太好
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务