[UVA][] 10273 - Eat or Not to Eat@Morris' Blog|PChome Online 人新台
2014-02-17 09:11:25| 人2,925| 回0 | 上一篇 | 下一篇

[UVA][] 10273 - Eat or Not to Eat

0 收藏 0 0 站台

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
__________________________________________________________________________________________
Rujia Liu

目描述:


每牛的生牛奶的量按照期性生,每天生最少的牛掉,如果有相同少的牛,一也不。

最後剩下牛,而最後一是第天的。

目解法:


由於期最多 10 天,最小公倍 2520 天。

每次 2520 天,查找每一天是否有牛可以,直到某循任何一牛都不成。


#include <stdio.h>
// For the values: 10, 9, 8, 7, 6, 5, 4, 3, 2
// The LCM is: 2520
int main() {
    int testcase;
    int n, i, j, k;
    int T[1005][15], Tn[1005];
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d", &n);
        for(i = 0; i < n; i++) {
            scanf("%d", &Tn[i]);
            for(j = 0; j < Tn[i]; j++)
                scanf("%d", &T[i][j]);
        }
        int killed[1005] = {};
        int LCM = 2520, days = 0, lastDay = 0;
        int hasKilled = 1, sum;
        while(hasKilled) {
            hasKilled = 0;
          &nbp; for(i = 0; i < LCM; i++) {
                days++;
                int mn = 0xfffffff, mncnt = 0, mnidx;
                for(j = 0; j < n; j++) {
                    if(killed[j])    continue;
                    int v = T[j][i%Tn[j]];
                    if(v < mn)
                        mn = v, mncnt = 0, mnidx = j;
                    if(v == mn)
                        mncnt++;
                }
                if(mncnt == 1) {
                    killed[mnidx] = 1;
                    lastDay = days;
                    hasKilled = 1;
                }
            }
        }
        for(i = 0, sum = 0; i < n; i++)
            sum += killed[i] == 0;
        printf("%d %d\n", sum, lastDay);
    }
    return 0;
}

台: Morris
人(2,925) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA][段] 10587 - Mayor's posters
此分上一篇:[UVA][排列合] 10232 - Bit-wise Sequence

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86