UVA 10273 - Eat or Not to Eat?(暴力)

原创 2013年12月02日 16:35:14

Problem E
Eat or not to Eat?
Input:
 Standard Input
Output: Standard Output

A young farmer has N cows, but they produced really really a very very small amount of milk. John cannot live on the milk they made, so he's planning to eat some of the 'worst' cows to get rid of hunger. Each day, John chooses the cow that produces the LEAST amount of milk on that day and eat them. If there are more than one cow with minimal milk, John will be puzzled and will not eat any of them (Yeah! That's GREAT!!).

The i-th cow has a cycle of production Ti. That means, if it produces L unit milk on one day, it will also produce L unit after Ti days -- If it will not be eaten during these day :-). Though John is not a clever man, he doubts whether the cows will be eventually eaten up, so he asks for your help. Don't forget that he will offer you some nice beef for that!

Input

The first line of the input contains a single integer T, indicating the number of test cases. (1<=T<=50) Each test case begins with an integer N(1<=N<=1000), the number of cows. In the following N lines, each line contains an integer Ti(1<=Ti<=10), indicating the cycle of the i-th cow, then Ti integers Mj(0<=Mj<=250) follow, indicating the amount of milk it can produce on the j-th day.

Output

For each test case in the input, print a single line containing two integers C, D, indicating the number of cows that will NOT be eaten, and the number of days passed when the last cow is eaten. If no cow is eaten, the second number should be 0.

Sample Input

1
4
4 7 1 2 9
1 2
2 7 1
1 2

Sample Output

2 6

题意:n头牛,每头有产奶周期,现在要杀牛,如果当天能找到产奶最小的牛且只数为1,就可杀,问最后剩几头牛和最后杀牛的天数。

思路:暴力,枚举每一天,周期为所有周期的最小公倍数,如果两次吃牛间隔超过一个周期,说明以后就肯定不会在杀牛了。

代码:

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
const int N = 1005, M = 15, MAXT = 2520;

int T, n, t[N], pro[N][M], day, vis[N];

void init() {
    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) {
	scanf("%d", &t[i]);
	for (int j = 0; j < t[i]; j ++)
	    scanf("%d", &pro[i][j]);
    }
}

void solve() {
    init();
    int sum = 0, dayv = -1;
    for (day = 0; day - dayv <= MAXT; day ++) {
	int Min = INF, count = 0, index = 0;
	for (int i = 0; i < n; i++) {
	    if (vis[i]) continue;
	    if (Min > pro[i][day % t[i]]) {
		Min = pro[i][day % t[i]];
		count = 1;
		index = i;
	    }
	    else if (Min == pro[i][day % t[i]]) {
		count ++;
	    }
	}
	if (count == 1) {
	    vis[index] = 1;
	    sum ++;
	    dayv = day;
	}
    }
    printf("%d %d\n", n - sum, dayv + 1);
}

int main() {
    scanf("%d", &T);
    while (T --) {
	solve();
    }
    return 0;
}


相关文章推荐

UVa10273 Eat or Not to Eat?

题意:N头奶牛,产奶有周期

ZOJ-1236 Eat or Not to Eat?

Eat or Not to Eat? Time Limit: 10 Seconds      MemoryLimit: 32768 KB A young farmer ha...

How to eat more Banana

How to eat more Banana 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述A group of researchers are...

nyoj232 How to eat more Banana (LIS变形)

刚开始我以为知道题始背包问题,可是后来不知怎么存储有效的数据,忍不住(唉,每次都这样,十几分钟想不出来就想看题解了,这就是现在为什么我还是那么菜的原因之一)看了题解,其实就是LIS(最长上升序列)变形...

air jordan pas cher not only did not eat hot dogs behavior for extra points

the Central Commission for Discipline Inspection announced the state-owned enterprise responsible fr...

uva10273(暴力模拟)

不知道为什么这题会在图伦里,纯暴力过了..

UVa 10469 To Carry or not to Carry (异或)

10469 - To Carry or not to Carry Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?opti...

Eat pray love

拒绝了我姐一起看电影的邀请,屋子里还回响着她的声音:“你就在家呆着吧!”,满是气愤和不满,我想人们做事什么时候能不从自己的角度出发,多些理解和包容,要我陪她看电影不去很正常,我有自己的生活习惯,我喜欢...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVA 10273 - Eat or Not to Eat?(暴力)
举报原因:
原因补充:

(最多只允许输入30个字)