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 ...
随机推荐
- error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).
用Visual Studio2015 编译时,遇到如下编译错误: error C2220: warning treated as error - no 'object' file generated ...
- thinkphp3.2.3 excel导出,下载文件,包含图片
关于导出后出错的问题 https://segmentfault.com/q/1010000005330214 https://blog.csdn.net/ohmygirl/article/detail ...
- 驱动程序调试方法之printk——自制proc文件(一)
首先我们需要弄清楚proc机制,来看看fs/proc/proc_misc.c这个文件,从入口函数开始看: proc_misc_init(void) #ifdef CONFIG_PRIN ...
- php$get中文汉字参数乱码
最近写了个简单的页面,从浏览器中传入中文参数(test.php?name=测试),不论怎么设置utf-8的页面中都显示乱码,google了一把也查到了不少解决办法,但是问题的原因到底是什么呢?没有人深 ...
- php计算两个坐标直线距离
function rad($d) { return $d * 3.1415926535898 / 180.0; } function GetDistance($lat1, $lng1, $lat2, ...
- 【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 基于 Android NDK 的学习之旅-----JNI LOG 打印
程序都是调出来的. 下面我介绍下JNI层的log打印方法的使用,类似与Android sdk提供的log 1.Android 应用层 MainActivity.java 主要功能代码 a) ...
- 【U205】最大值
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 找到一个数组的最大值的一种方法是从数组开头从前到后对数组进行扫描,令max=a[0](数组下表从0.. ...
- 【t084】数列
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 一个数列定义如下:f(1) = 1,f(2) = 1,f(n) = (A * f(n - 1) + B ...
- ITFriend创业败局(一):选择创业方向和寻找合伙人,创业失败的2个关键点
这次创业惨淡收场,最主要的原因是没有选择一个合适的创业方向,没有找到合适的创业合伙人. 首先要说到创业方向,因为不同的创业方向需要组建不同的创业团队.我个人比较偏好,软件.网络.互联网等有一 ...