uva10273(暴力模拟)
来源:互联网 发布:网络教研总结 编辑:程序博客网 时间:2024/05/16 05:57
不知道为什么这题会在图伦里,纯暴力过了..
题目的意思就是好几只羊,他们每天产奶,
产奶是有周期的,例如4 1 2 3 4,就是周期为 4 ,第一天产1 ,第二天产2 ,第三天产3 ,第四天产4 ,第五天又是1.
然后每一天,这个人都会选产奶最少的干掉.但是如果最小的同时存在两个,这天就不杀.
求最后剩下几只不会被杀, 还有最后杀的那只是在第几天.
直接模拟..
有一点就是要求出天数的最大公倍数.
如果最大公倍数的天都一只都没杀,那就不用继续了.就永远死不了了..
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int N = 1000;const int INF = 0x3f3f3f3f;int day[N];int vis[N];int amount[N][250];int n;int cul(int x , int y) {int temp;if(x > y) {temp = x ;x = y;y = temp;}temp = 1;while(y != 0) {temp = x % y;x = y;y = temp;}return x;}int cycle() {//sort(day , day + n);int res = day[0];for (int i = 1 ; i < n ;i++) {res = res * day[i] / cul(res , day[i]);}return res ;}int main () {int t;scanf("%d",&t);while(t--) {memset(vis,0,sizeof(vis));scanf("%d",&n);for (int i = 0 ; i < n ;i++) {scanf("%d",&day[i]);for (int j = 0 ; j < day[i] ; j++) {scanf("%d",&amount[i][j]);}}int res = 0;int ans = 0;int k = 0 ;int kill = 0;int c = cycle();bool eat;while(1) {int minn = INF;for (int i = 0 ; i < n ;i++) {if(vis[i])continue;if(amount[i][res % day[i]] < minn) {eat = true;minn = amount[i][res % day[i]];kill = i;}else if(amount[i][res % day[i]] == minn) {eat = false;}}if (eat) {vis[kill] = 1;ans++;k = 0;}else {k++;if(k == c) {res -= c ;break;}}res++;}printf("%d %d\n",n - ans , res + 1);}}
0 0
- uva10273(暴力模拟)
- 暴力uva10273
- UVA10273 - Eat or Not to Eat?(暴力)
- HDU **** 暴力模拟
- HLJUOJ1117(暴力模拟)
- HDU2555(模拟暴力)
- uva1504(模拟+暴力)
- 【模拟】【暴力】[COCI]排序
- 模拟暴力 uva12108
- HDU6168(暴力模拟)
- POJ 1013 小水题 暴力模拟
- 1035 Spell checker 暴力模拟
- UVA 140 Bandwidth 暴力模拟
- Uva10288(概率期望+暴力模拟)
- HDU 5071 Chat 暴力模拟
- [CodeForces318C]Perfect Pair[模拟][暴力]
- hdu 5386 Cover 暴力模拟
- POJ-1012-Joseph-暴力/模拟
- 更新OSX 10.10 Yosemite之后修复Bitnami Stacks中的MySQL服务
- VC++的链接错误LNK2001
- Linux 指令学习之 关机、注销和重启
- 第十二周项目三(5)二进制
- VC++调试方法和技巧
- uva10273(暴力模拟)
- 解决Ubuntu系统中文乱码显示问题
- VC小技巧20个
- Redis主从复制
- World Wind Java开发之四——搭建本地WMS服务器
- CF488C Fight the Monster
- 探索推荐引擎内部的秘密,第 1 部分: 推荐引擎初探
- 关键字this与super
- poj3279开关问题