133UVa救济金发放——静态链表
来源:互联网 发布:2017淘宝总额 编辑:程序博客网 时间:2024/04/30 04:20
注意: while(used[idx1])
idx1 = next[idx1];
while(used[idx2])
idx1 = next[idx1];
while(used[idx2])
idx2 = pre[idx2];
因为next[idx1]有可能是idx2,被删了。所以要用used来记录哪些已被删了。(next[idx1]、pre[idx2]有可能是原来的idx2,idx1,被删了~)
#include <stdio.h>int main() { int i, n, k, m; int next[30], pre[30]; while(scanf("%d %d %d", &n, &k, &m) == 3) { if(n == 0 && k == 0 && m == 0) break; for(i = 1; i <= n; i++) next[i] = i+1, pre[i] = i-1; next[n] = 1, pre[1] = n; int idx1 = 1, idx2 = n, used[30] = {}; int flag = 0; while(n) { for(i = 1; i < k; i++) idx1 = next[idx1]; for(i = 1; i < m; i++) idx2 = pre[idx2]; if(flag) putchar(','); flag = 1; if(idx1 != idx2) { printf("%3d%3d", idx1, idx2); used[idx1] = used[idx2] = 1; n -= 2; next[pre[idx1]] = next[idx1]; pre[next[idx1]] = pre[idx1]; next[pre[idx2]] = next[idx2]; pre[next[idx2]] = pre[idx2]; } else { used[idx1] = 1; printf("%3d", idx1); next[pre[idx1]] = next[idx1]; pre[next[idx1]] = pre[idx1]; n--; } if(n == 0) break; while(used[idx1]) idx1 = next[idx1]; while(used[idx2]) idx2 = pre[idx2]; } puts(""); } return 0;}
0 0
- 133UVa救济金发放——静态链表
- 133UVa救济金发放——动态链表
- 133UVa救济金发放——不用链表
- UVA 133 救济金发放
- uva 133 救济金发放
- UVa 133 救济金发放
- UVa 133 救济金发放
- Uva 133 救济金发放
- uva 133 发放救济金
- 救济金发放 UVA 133
- 救济金发放(uva-133)
- UVA-4.3-救济金发放-133
- UVa - 133 - The Dole Queue(救济金发放)
- 救济金发放 (The Dole Queue, UVa 133)
- UVa 133 The Dole Queue(救济金发放)
- 救济金发放(The Dole Queue, UVa 133)
- 救济金发放 (The Dole QUEUE UVa 133)
- UVA 133 The Dole Queue(救济金发放)
- 三次Beizer曲线拟合算法
- css 固定HTML表格的宽度
- 搜索引擎之倒排索引
- bzoj 2154: Crash的数字表格 莫比乌斯反演
- CCF 2014 9-1 相邻数对
- 133UVa救济金发放——静态链表
- netty介绍
- 适配常用代码
- 内存溢出之Tomcat内存配置
- Intellij idea: servlet cannot be resolved to a type
- restTemplate获取gizp字符串数据和解码
- Intellij IDEA 一些不为人知的技巧
- 在eclipse中如何连链接mysql数据库
- 4723: [POI2017]Flappy Bird