UVa 10935 - Throwing cards away I
2013-05-03 15:13
274 查看
《算法竞赛入门经典》6.1的题目。题目大意:给n张牌,放成一叠,从上到下编号从1到n,当至少还有两张牌时,丢弃最上面的牌,然后把新的最上面的牌放到最下面,一直重复,直到只剩下一张牌,输出丢弃牌的序列。
用队列进行模拟,不过第一次提交的时候PE了,格式说明一下:
View Code
用队列进行模拟,不过第一次提交的时候PE了,格式说明一下:
”Discarded cards:“,然后每一数字前加一个空格,第一个数字之后的数字要在空格前加逗号。代码如下:
View Code
#include <cstdio> #include <cstdio> #include <queue> using namespace std; const int maxn = 60; queue<int> q; int main() { #ifdef LOCAL freopen("in", "r", stdin); #endif int n; int ans[maxn]; while(scanf("%d", &n) != EOF && n) { for(int i = 1; i <= n; i++) q.push(i); int k = 0; while(!q.empty()) { ans[k++] = q.front(); q.pop(); int t = q.front(); q.pop(); q.push(t); } printf("Discarded cards:"); for(int i = 0; i < n-1; i++) { if(i) printf(","); printf(" %d", ans[i]); } printf("\nRemaining card: %d\n", ans[n-1]); } return 0; }
相关文章推荐
- (1.1.7)UVA 10935 Throwing cards away I(直叙式模拟)
- Throwing cards away I UVA - 10935
- UVa 10935 - Throwing cards away I
- Throwing cards away I UVA - 10935
- UVa10935 - Throwing cards away I
- Uva 10935 Throwing cards away I
- UVA_10935: Throwing cards away I
- uva 10935 throwing cards away <queue>
- Throwing cards away I 卡牌游戏 UVA 10935
- UVa 10935 - Throwing cards away I
- UVA -10935-卡片游戏-Throwing cards away
- UVA10935 - Throwing cards away I
- UVA 10935 - Throwing cards away I
- UVa 10935 Throwing cards away 1
- Uva10935——Throwing cards away I
- UVA10935 Throwing cards away I【模拟+queue+循环队列】
- UVA - 10935-Throwing cards away I
- UVa---------10935(Throwing cards away I)
- Uva 10935 Throwing cards away I
- UVA 10935 - Throwing cards away I