Idea: brute-force Solution
Analysis:
1. The number of cows that have not been eaten must be the number of days that have been last eaten.
2. No other method can only be violent. For n cycles of native cattle, obtain the minimum public multiple, And then solve the problem by brute force within 2 Public multiples.
Code:
#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 1010;int n , lcm;vector<int>v[MAXN];bool isEat[MAXN];int gcd(int a , int b){ return b == 0 ? a : gcd(b , a%b);}void init(){ memset(isEat , false , sizeof(isEat)); for(int i = 0 ; i < MAXN ; i++) v[i].clear();}void solve(){ int index = 0; int notEat = n; int numDay = 0; while(index < 2*lcm){ int min = 1<<30; int minIndex = -1; for(int i = 0 ; i < n ; i++){ if(!isEat[i]){ int size = v[i].size(); int tmp = v[i][index%size]; if(min > tmp){ min = tmp; minIndex = i; } else{ if(min == tmp) minIndex = -1; } } } index++; if(minIndex != -1){ notEat--; numDay = index; isEat[minIndex] = true; } } printf("%d %d\n" , notEat , numDay);}int main(){ int Case , m , x; scanf("%d" , &Case); while(Case--){ scanf("%d" , &n); init(); bool isFirst = true; for(int i = 0 ; i < n ; i++){ scanf("%d" , &m); if(isFirst){ lcm = m; isFirst = false; } lcm = lcm/gcd(lcm , m)*m; while(m--){ scanf("%d" , &x); v[i].push_back(x); } } solve(); }}