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 ...
随机推荐
- 如何在 BitNami 中创建多个 WEB 应用?(转)
本文最后更新于2015年7月14日,已超过半年没有更新,如果内容失效,请反馈,谢谢! 如您所知,BitNami 为诸多开源 WEB 应用提供集成环境的一键安装解决方案,像著名的开源 WEB 程序 Wo ...
- Android多线程研究(8)——Java5中Futrue获取线程返回结果
我们先来看一下ExecutorService中的执行方法: 在上一篇中我们使用了execute方法启动线程池中的线程执行,这一篇我们来看看submit方法的使用:submit提交一个返回值的任务用于执 ...
- 手机浏览器 input 输入框 数字
其实很简单了啦 type="tel"就行了呢 如果是type="number"其实不好用
- 【u019】排序(sort)
[问题描述] 一个不同的值的升序排序数列指的是一个从左到右元素依次增大的序列,例如,一个有序的数列A,B,C,D 表示A<B,B<C,C<D.在这道题中,我们将给你一系列形如A< ...
- [RxJS] Add debug method to Observable in TypeScript
Observable.prototype.debug = function(message: any) { return this.do( (next) => { if(!environment ...
- (转自aierong原创技术随笔)sqlserver字符串拆分(split)方法汇总
sqlserver字符串拆分(split)方法汇总 --方法0:动态SQL法declare @s varchar(100),@sql varchar(1000)set @s='1,2,3,4,5, ...
- 王立平--TableLayout
效果: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android= ...
- 移动CMPP3.0接口
前段时间准备上线期,同事接了个联调CMPP3.0短信接口的任务,但是一直不成功,抽时间给解决了一下,记录下其中几个要点: 1.短信网关厂家需要提供参数: #网关IP地址 ismgIp=1.1.1.1# ...
- 虚拟机的ip网络设置的选择
首先看一下vm的这几个设置 通过截图可以基本看到几个网络设置的区别,具体体现在虚拟机装好以后,网络设置会多出两个适配器,不同模式会分配不同区段的ip,需要固定时主要区段要求 所以总结一下 1.桥连,适 ...
- sql数据库时间转换convert
CONVERT CONVERT将某种数据类型的表达式显式转换为另一种数据类型. 严格来说,CONVERT不属于日期处理函数,只是它被经常用于日期处理中,所以这里把它列入了其他日期处理函数,下面是CON ...