题意略;

先暴力打表发现规律

N=1 ans=1
N=2 ans=2
N=3 ans=2
N=4 ans=4
N=5 ans=2
N=6 ans=4
N=7 ans=6
N=8 ans=8
N=9 ans=2
N=10 ans=4
N=11 ans=6
N=12 ans=8
N=13 ans=10
N=14 ans=12
N=15 ans=14
N=16 ans=16
N=17 ans=2
N=18 ans=4
N=19 ans=6
N=20 ans=8
N=21 ans=10
N=22 ans=12
N=23 ans=14
N=24 ans=16
N=25 ans=18
N=26 ans=20
N=27 ans=22
N=28 ans=24
N=29 ans=26
N=30 ans=28
N=31 ans=30
N=32 ans=32

这规律很明显了就略了。。直接上代码了

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 500003
vector<int>tab[];
int num[];
int N;
void init()
{
for (int i=;i<;i++) tab[i].clear();
tab[].push_back();
for (int i=;i<;i++)
{
int limit=<<i;
int cas=;
while (cas<=limit)
{
tab[i].push_back(cas);
cas+=;
}
}
num[]=;
for (int i=;i<;i++) num[i]=num[i-]+tab[i].size();
}
int main()
{
init();
while (scanf("%d",&N)!=EOF)
{
if (N==) break;
if (N==) {puts("");continue;}
int cas=,i;
for ( i=;i<;i++)
{
cas+=tab[i].size();
if (cas>=N) break;
}
int tmp=N-num[i-];
printf("%d\n",tab[i][tmp-]);
}
return ;
}

UVA 10940 Throwing cards away II的更多相关文章

  1. UVA10940 - Throwing cards away II(找到规律)

    UVA10940 - Throwing cards away II(找规律) 题目链接 题目大意:桌上有n张牌,依照1-n的顺序从上到下,每次进行将第一张牌丢掉,然后把第二张放到这叠牌的最后.重复进行 ...

  2. 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 ...

  3. UVa 10935 Throwing cards away I【队列】

    题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...

  4. uva 10935 throwing cards away <queue>

    Given is an ordered deck of    n    cards numbered 1 to    n    with card 1 at the top and card    n ...

  5. Uva 10935 Throwing cards away I

    题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最 ...

  6. 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 ...

  7. 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 ...

  8. [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...

  9. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

随机推荐

  1. 自定义注解不能拦截controller层

    1,首先在springMVC的配置文件中,webapp/WEB-INF/servlet.xml,加上AOP的相关内容: <beans xmlns="http://www.springf ...

  2. 通过Aspose.Word和ZXING生成复杂的WORD表格

    1.前言 这是我之前做的一个项目中要求的功能模块,它的需求是生成一个WORD文档,需要每页一个表格并且表格中需要插入文字.条形码和二维码等信息,页数可控制.具体的效果如下图所示: 可以看到有以下几点是 ...

  3. 使用CSS3制作各种形状

    CSS3的一个非常酷的特性是允许我们创建各种规则和不规则形状的图形,从而可以减少图片的使用.以前只能在Photoshop等图像编辑软件中制作的复杂图形现在使用CSS3就可以完成了.通过使用新的CSS属 ...

  4. 03019_过滤器Filter

    1.Filter的简介 (1)Filter是对客户端访问资源的过滤,符合条件放行,不符合条件不放行,并且可以对目标资源访问前后进行逻辑处理: (2)快速入门步骤 ①编写一个过滤器的类实现Filter接 ...

  5. Field 'flag' doesn't have a default value错误

    错误代码: java.sql.SQLException: Field 'flag' doesn't have a default value at com.mysql.jdbc.SQLError.cr ...

  6. <<程序猿健康指南>> 笔记

    序言: 长时间对着电脑工 作.一天下来基本不怎么走动的人,患高血压及 2 型糖尿病的风险远高于其他人群, 这两种疾病会对人体的健康产生长久的严重影响,还会增加心脏病及中风的几率. 前言: 阿米什人(A ...

  7. 实际遭遇GC回收造成的Web服务器CPU跑高

    今天下午有段时间访问园子感觉不如以前那么快的流畅,上Web服务器一看,果然,负载均衡中的1台云服务器CPU跑高. 上图中红色曲线表示的是CPU占用率.正常情况下,CPU占用率一般在40%以下. 这台云 ...

  8. 《Cracking the Coding Interview》——第17章:普通题——题目4

    2014-04-28 22:32 题目:不用if语句或者比较运算符的情况下,实现max函数,返回两个数中更大的一个. 解法:每当碰见这种无聊的“不用XXX,给我XXX”型的题目,我都默认处理的是int ...

  9. Windows下如何解决git bash的默认home目录路径问题

    转自:http://blog.csdn.net/lucien_zhou/article/details/62069246 为了解决这个问题,我在网上找了好久,尝试过按网上其他人所述,修改 git 安装 ...

  10. Jmeter beanshell preprocessor随机添加任意多个请求参数

    介绍下本次使用beanshell preprocessor的原因: 1.系统下可添加产品,一个产品可以有多个产品主题(比如:产品A(杭州三日游)拥有三个主题(研学.红学.夏令营)),我们在每次添加产品 ...