UVA 10935 Throwing cards away I 【数据结构】【模拟】
2017-01-14 21:49
411 查看
题目链接:https://vjudge.net/problem/UVA-10935
题目大意:
桌上有n张牌,从第一张牌开始,从上往下一次编号为1~n,当至少还剩下两张牌是进行以下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后,求扔掉的牌所组成的序列以及最后剩下的牌。
题目思路:
原来以为是模拟,直接上暴力,AC之后反倒想明白其实是一个队列…
致IQ == 0的我…
唯一需要注意的这么一组数据:
1
实际的输入应该是
Discarded cards:
Remaining card: 1
其实这个漏洞我是从 udebug 中发现的,udebug这道题的第一个数据很精彩,给好评~
剩下的没什么了,就是纯模拟。
附代码:
题目大意:
桌上有n张牌,从第一张牌开始,从上往下一次编号为1~n,当至少还剩下两张牌是进行以下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后,求扔掉的牌所组成的序列以及最后剩下的牌。
题目思路:
原来以为是模拟,直接上暴力,AC之后反倒想明白其实是一个队列…
致IQ == 0的我…
唯一需要注意的这么一组数据:
1
实际的输入应该是
Discarded cards:
Remaining card: 1
其实这个漏洞我是从 udebug 中发现的,udebug这道题的第一个数据很精彩,给好评~
剩下的没什么了,就是纯模拟。
附代码:
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int size = 505; int n, poker[size]; int main() { // freopen("10935.out","w", stdout); (udebug) while( scanf("%d", &n), n ) { int beg = 1, end = n; memset(poker, 0, sizeof(poker)); printf("Discarded cards:"); for ( int i = 1; i <= n; i++ ) poker[i] = i; if( beg != end ) { while( beg < end-1 ) { printf(" %d,", poker[beg]); poker[++ end] = poker[beg+1]; beg += 2; // printf(" %d %d\n", beg, end); } printf(" %d", poker[beg]); } printf("\nRemaining card: %d\n", poker[end]); } return 0; }
相关文章推荐
- UVa 10935 - Throwing cards away I(模拟)
- UVa 10935 Throwing cards away I【队列模拟】
- (1.1.7)UVA 10935 Throwing cards away I(直叙式模拟)
- UVa 10935 Throwing cards away 1
- Uva - 10935 - Throwing cards away I
- UVA 10935 - Throwing cards away I
- Throwing cards away I 卡牌游戏 UVA 10935
- UVA10935 Throwing cards away I【模拟+queue+循环队列】
- UVa10935-Throwing cards away I-卡片游戏-队列的运用
- UVA10935 Throwing cards away I【模拟+queue+循环队列】
- UVA 10935 Throwing cards away I
- UVa 10935 - Throwing cards away I
- 经典第五章 习题 5-3 UVA 10935 Throwing cards away I(队列的简单应用)
- UVa---------10935(Throwing cards away I)
- 卡片游戏(Throwing cards away I,UVa 10935)
- UVA -10935-卡片游戏-Throwing cards away
- Uva 10935 Throwing cards away I
- UVa 10935 - Throwing cards away I
- UVA 10935 Throwing cards away
- UVa 10935 - Throwing cards away I