栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1236 Eat or Not to Eat?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1236 Eat or Not to Eat?

#include<cstdio>#include<cstring>using namespace std;namespace{int gcd(int a, int b){if (!a)return b;return gcd(b % a, a);}int lcm(int a, int b){return a * b / gcd(a, b);}int length(int *mp){int res = 1;for (int i = 1; i <= 10; i++)if (mp[i])res = lcm(res, i);return res;}}int main(){int T, a[1000][10], c[1000], mp[11];bool eat[1000];scanf("%d", &T);while (T--){int N;scanf("%d", &N);memset(mp, 0, sizeof(mp));memset(eat, 0, sizeof(eat));for (int i = 0; i < N; i++){scanf("%d", &c[i]);mp[c[i]]++;for (int j = 0; j < c[i]; j++)scanf("%d", &a[i][j]);}bool end = false;int day = 0, eated = 0;while (!end){int dd, len = length(mp);for (dd = 0; dd < len; dd++){int minn = 300, count = 0, eatindex = -1;for (int i = 0; i < N; i++){if (eat[i])continue;int index = day % c[i];if (a[i][index] < minn){minn = a[i][index];count = 1;eatindex = i;}else if (a[i][index] == minn)count++;}day++;if (count == 1){eated++;eat[eatindex] = true;mp[c[eatindex]]--;break;}}if (dd == len){day -= len;end = true;}if (eated == N)end = true;}printf("%d %dn", N - eated, day);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号