UVA 239 - Tempus et mobilius. Time and motion(置换周期)
来源:互联网 发布:网页在线视频下载软件 编辑:程序博客网 时间:2024/05/30 22:48
UVA 239 - Tempus et mobilius. Time and motion
题目链接
题意:这题题意也是吊得飞起,看了老半天,大概是这样:
有一个放球的队列,和3个轨道(说白了就是栈),一个容纳5,1个12,1个12,每1分钟队列出一个小球,放入栈,如果放入5的满了,就把5的放回队列,头一个放入12的,如果12的满了,就把12的放回队列,头一个放入另一个12的栈,如果又满了,就全部放回队列(头一个最后放回),问多少天之后,队列中小球会回复原来的状态
思路:先是模拟求出一天的情况,对应一个置换,然后就是求置换中循环的最大公倍数即可了
代码:
#include <stdio.h>#include <string.h>#include <queue>#include <stack>using namespace std;const int N = 7005;int n, next[N], vis[N];long long gcd(long long a, long long b) {if (!b) return a;return gcd(b, a % b);}long long lcm(long long a, long long b) {return a / gcd(a, b) * b;}int main() {while (~scanf("%d", &n) && n) {queue<int> Q;stack<int> mins, fives, hours;for (int i = 0; i < n; i++)Q.push(i);for (int t = 0; t < 1440; t++) {int now = Q.front();Q.pop();if (mins.size() == 4) {for (int i = 0; i < 4; i++) {Q.push(mins.top());mins.pop(); } if (fives.size() == 11) { for (int i = 0; i < 11; i++) { Q.push(fives.top()); fives.pop(); } if (hours.size() == 11) { for (int i = 0; i < 11; i++) { Q.push(hours.top()); hours.pop(); } Q.push(now); } else hours.push(now); } else fives.push(now); } else mins.push(now); } for (int i = 0; i < n; i++) { next[i] = Q.front(); Q.pop();}memset(vis, 0, sizeof(vis));long long ans = 1;for (int i = 0; i < n; i++) {if (!vis[i]) {long long cnt = 1;vis[i] = 1;int t = next[i];while (!vis[t]) {cnt++;vis[t] = 1;t = next[t]; } ans = lcm(ans, cnt); } } printf("%d balls cycle after %lld days.\n", n, ans); }return 0;}
1 0
- UVA 239 - Tempus et mobilius. Time and motion(置换周期)
- uva 239 - Tempus et mobilius. Time and motion(置换)
- POJ 1879 - Tempus et mobilius Time and motion【置换群】
- POJ1879 Tempus et mobilius Time and motion【置换群】
- Tempus et mobilius Time and motion
- poj 1879.Tempus et mobilius Time and motion
- poj 1879 Tempus et mobilius Time and motion
- POj 1879 Tempus et mobilius Time and motion (模拟+群)
- Tempus et mobilius Time and motion栈与队列
- poj 1879 Tempus et mobilius Time and motion
- POJ 1879 Tempus et mobilius Time and motion(黑书,小球钟)
- POJ 1879 Tempus et mobilius Time and motion 队列和栈
- JOJ 1060: Time And Motion 解题报告
- Real-Time Video Super-Resolution with Spatio-Temporal Networks and Motion Compensation 论文笔记
- 交付周期 lead-time
- UVA 10116 - Robot Motion
- UVa 10116 - Robot Motion
- UVa 10515 - Powers Et Al.
- Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等
- 磁盘坏道的处理
- JavaEE 技术选型建议,服务器配置,部署策略
- 与PHP通信
- 五.指针与结构
- UVA 239 - Tempus et mobilius. Time and motion(置换周期)
- 【转】细究lua闭包->搞清本质才是王道
- gcc命令
- 仿广告或教程页面下的圆点(或图片等)切换指示器实现原理,例Android-ViewPagerIndicator
- 如何获取 GridView 编辑状态下单元格里的值
- 【LeetCode】Integer to Roman
- ssssss
- poj2253 Frogger 图论,Floyd
- 斯坦福大学Andrew Ng教授主讲的《机器学习》公开课观后感