UVA10940 - Throwing cards away II(找到规律)
UVA10940 - Throwing cards away II(找规律)
题目大意:桌上有n张牌,依照1-n的顺序从上到下,每次进行将第一张牌丢掉,然后把第二张放到这叠牌的最后。重复进行这种操作。直到仅仅剩下一张牌。
解题思路:仅仅能先暴力。将前面小点的n打印出来。看看有什么规律。
规律:f【2^k + mod] = 2*mod;(mod > 0); n = 1须要特判.
代码:
#include <cstdio>
#include <cstring>
const int maxn = 5e5 + 5;
int f[maxn];
void init () {
int tmp = 1;
f[1] = 1;
for (int i = 2; i <= maxn - 5; i++) {
if(i > tmp * 2) {
tmp *= 2;
f[i] = 2 * (i - tmp);
} else
f[i] = 2 * (i - tmp);
}
}
int main () {
init();
int n;
while (scanf ("%d", &n) && n) {
printf ("%d\n", f[n]);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
UVA10940 - Throwing cards away II(找到规律)的更多相关文章
- UVA 10940 Throwing cards away II
题意略: 先暴力打表发现规律 N=1 ans=1N=2 ans=2N=3 ans=2N=4 ans=4N=5 ans=2N=6 ans=4N=7 ans=6N=8 ans=8N=9 ans=2N=10 ...
- Throwing cards away I
Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top a ...
- UVa 10935 - Throwing cards away I (队列问题)
原题 Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the to ...
- UVa---------10935(Throwing cards away I)
题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 ...
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...
- Throwing cards away I uva1594
Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the t ...
- 紫书第五章训练3 D - Throwing cards away I
D - Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top ...
- G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;
/** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...
- HDU 1165 Eddy's research II (找规律)
题意:给定一个表达式,然后让你求表达式的值. 析:多写几个就会发现规律. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400000 ...
随机推荐
- 项目中使用Prism框架
Prism框架在项目中使用 回顾 上一篇,我们介绍了关于控件模板的用法,本节我们将继续说明WPF更加实用的内容,在大型的项目中如何使用Prism框架,并给予Prism框架来构建基础的应用框架,并且 ...
- Linux下kill进程脚本
Linux下kill进程脚本 在Linux有时会遇到需要kill同一个程序的进程,然而这个程序有多个进程,一一列举很是繁琐,使用按名字检索,统一kill Perl脚本 使用方法 kill_all.pl ...
- HTML5开发移动web应用——SAP UI5篇(9)
之前我们对于app的构建都是基于显示的.如今我们来格式化一下,引入很多其它的SAP UI5组件概念.这使得APP的一个界面更有层次性.更像是一个手机应用的界面,而且更好地使用SAP UI5中提供的功能 ...
- [Angular] Using useExisting provider
Unlike 'useClass', 'useExisting' doesn't create a new instance when you register your service inside ...
- 详解springmvc控制登录用户session失效后跳转登录页面
springmvc控制登录用户session失效后跳转登录页面,废话不多少了,具体如下: 第一步,配置 web.xml <session-config> <session-timeo ...
- ios开发事件处理之:五:事件的响应
- Cocos2D-html5 公布游戏js编译为jsc
搞了老半天.这么回事啊.工具都在tools中. jsb模式下是通过打包spidermonkey来执行JS代码的. JS文件都在assets目录中.我们都知道assets目录.打包后的结果,将apk包解 ...
- vs 错误提示及解决方案
错误: 应输入";" 错误原因,宏展开出现错误:
- Angular.js回想+学习笔记(1)【ng-app和ng-model】
Angular.js中index.html简单结构: <!doctype html> <html ng-app> <head> <script src=&qu ...
- 【a901】滑雪
Time Limit: 10 second Memory Limit: 2 MB 问题描述 滑雪是一项非常刺激的运动,为了获得速度,滑雪的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待 ...