南邮 OJ 1097 卡片游戏
来源:互联网 发布:nginx rewrite last 编辑:程序博客网 时间:2024/05/16 17:34
卡片游戏
时间限制(普通/Java) : 2000 MS/ 6000 MS 运行内存限制 : 65536 KByte
总提交 : 1372 测试通过 : 268
总提交 : 1372 测试通过 : 268
比赛描述
桌上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号为1~n。当至少还剩两张牌时进行以下操作:把第一张扔掉,然后把新的第一张放到整叠牌的最后。
输入
输入n,n≤1000000。
输出
输出每次扔掉的牌,以及最后剩下的牌。
样例输入
7
样例输出
1 3 5 7 4 2 6
题目来源
刘汝佳《算法竞赛入门经典》,编自UVa10935 Throwing cards away I
#include<iostream>using namespace std;struct link_node{long i;link_node* next;};int main(){long n,i;link_node *head,*tail,*p;cin>>n;if(n==1){cout<<1<<endl;return 0;}if(n==2){cout<<1<<" "<<2<<endl;return 0;}head = new link_node();head->i = 1;tail = head;for(i=2;i<=n;++i){p = new link_node();p->i = i;tail->next = p;tail = p;}while(head->next!=tail){cout<<head->i<<" ";p = head;head = head->next;delete p;p = head;head = head->next;tail->next = p;tail = p;}cout<<head->i<<" "<<tail->i<<endl;}
0 0
- 南邮 OJ 1097 卡片游戏
- 南邮NOJ卡片游戏
- 1097卡片游戏&queue队列
- oj刷题-2845: 编程题AB-卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏!!!
- 卡片游戏
- 卡片游戏
- 卡片游戏
- 卡片游戏
- JZOJ 3463 军训
- C/C++语言中Static的作用详述
- Android触摸屏事件派发机制详解与源码分析一(View篇)onTouch,onClick,ontouchevent
- Windows Phone 一 初学者的心得
- iOS开发 将图片打包编码以便上传
- 南邮 OJ 1097 卡片游戏
- Blackboard 与MathType之间的转换技巧
- recyclerview联动滑动 关键代码
- Unicode 下char*与CString相互转换
- 如何配置Vimperator
- html有序的表标签,type的值的设置
- JS的数组
- 重启linux下的oracle数据库
- nginx进程模型