标签:des style http strong os width
Description
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‘ cowsto get rid of hunger. Each day, John chooses the cow that produces the LEAST amount of milk on that dayand eat them. If there are more than one cow with minimal milk, John will be puzzled and will not eatany 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, itwill 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
1Sample Output
2 6Rujia Liu
题意:已知有n头牛,每个牛有自己的产奶周期,然后每天杀一头,找最低产奶量的杀,如果有两个一样少的话,今天就不杀,求最后剩下几头和最后杀的时间
思路:在2*lcm里面暴力枚举,lcm表示所有周期的最小公倍数,在2倍周期的天数里我们就可以匹配到所有的可能,就是a牛第几天的产奶量和b牛第几天的产奶比较
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <vector> using namespace std; const int MAXN = 1010; const int INF = 0x3f3f3f3f; int n, lcm; vector<int> v[MAXN]; int vis[MAXN]; int gcd(int a, int b) { return b==0?a:gcd(b, a%b); } int main() { int t; scanf("%d", &t); while (t--) { scanf("%d", &n); memset(vis, 0, sizeof(vis)); for (int i = 0; i <= n; i++) v[i].clear(); int m, d, flag = 1; for (int i = 0; i < n; i++) { scanf("%d", &m); if (flag) { flag = 0; lcm = m; } lcm = lcm/gcd(lcm, m)*m; for (int j = 0; j < m; j++) { scanf("%d", &d); v[i].push_back(d); } } int cur = 0, cnt = n, day = 0; while (day <= 2*lcm) { int Min = INF; int minIndex = -1; for (int i = 0; i < n; i++) { if (!vis[i]) { int size = v[i].size(); int tmp = v[i][day%size]; if (Min > tmp) { Min = tmp; minIndex = i; } else if (Min == tmp) minIndex = -1; } } day++; if (minIndex != -1) { cnt--; cur = day; vis[minIndex] = 1; } } printf("%d %d\n", cnt, cur); } return 0; }
UVA - 10273 Eat or Not to Eat?,布布扣,bubuko.com
UVA - 10273 Eat or Not to Eat?
标签:des style http strong os width
原文地址:http://blog.csdn.net/u011345136/article/details/37936307