【SPOJ-YOUTUBE】Youtube【倍增】
来源:互联网 发布:现代战争6网络出错 编辑:程序博客网 时间:2024/04/29 00:58
题意:
给出n个人,k个点,每个点指向的点(即每个点的出度为1),n个人的初始位置。每一分钟每个人都会走向当前点的指向点。问M分钟后每个人在哪个点。
考虑倍增。
知道每个点第2 ^ 0步在哪,就可以得到每个点走2 ^ 1在哪,然后一直推到2 ^ M步。
因为题意关系,似乎M需要先减一,因为一开始也算一分钟。
很久以前的代码风格,看上去也真是短(笑
#include <cstdio>#define rec(i, x, n) for(int i = x; i <= n; i++)const int maxn = 100005, maxd = 32;int n, k, m, f[maxn][maxd + 1], s[maxn];inline int iread() {int f = 1, x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';return f * x;}int main() {n = iread(); k = iread(); m = iread(); --m;rec(i, 1, n) s[i] = iread();rec(i, 1, k) f[i][0] = iread();rec(j, 1, maxd) rec(i, 1, k) f[i][j] = f[f[i][j - 1]][j - 1];rec(i, 1, n) {int u = s[i];for(int i = m, j = 0; i; i >>= 1, j++) if(i & 1) u = f[u][j];printf("%d ", u);}return 0;}
0 0
- 【SPOJ-YOUTUBE】Youtube【倍增】
- YouTube
- YouTube:
- YouTube
- YouTube
- YouTube
- YouTube Architecture.YouTube架构
- Youtube Supervote
- YouTube AIO
- About YouTube
- Youtube原理
- YouTube Architecture
- peoplesoft youtube
- YouTube 架构
- YouTube集成
- Youtube下载
- 使用 Youtube-dl 来下载YouTube视频
- 使用youtube-dl下载YouTube视频
- prototype
- 最大公约数与最小公倍数
- CodeForces 630 L. Cracking the Code(水~)
- HDU 4751 Divide Groups(判断二分图)
- json数据格式
- 【SPOJ-YOUTUBE】Youtube【倍增】
- 155. Min Stack
- hdu 1281(二分图求匹配)
- 用户是怎样访问我们的系统
- PHP序列化反序列化serialize和unserialize函数
- 浏览器加载和渲染html的顺序
- hadoop多文件格式输入(MultipleInputs)
- volatile的特性
- Monad transformers