题目描述
A想玩个游戏,游戏规则是,有n个人,编号从1-n,一字排开,站在奇数位置的人淘汰,剩下的人再一字排开,站在奇数位置的人淘汰,以此重复几次,最后只剩最后一个人,问最后一个人的编号是多少?
输入
输入一个正整数n(≤n≤1e100);
输出
输出一个整数,代表最后剩余的编号。
样例输入 样例输出

首先注意到数据范围特别大,需要用字符串读入

每次淘汰完一轮后剩下的第一个数总是2的倍数,有这个规律,利用大数乘法和大数除法解决

 1 #include<stdio.h>
2 #include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define N 1010
char str[N];
int arr[N];
int num[N];
int main()
{
int i;
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
for(i=;i<len;i++)
arr[i]=str[i]-'';
int m=,flag=;
num[]=;
while((arr[len-]!=)||(flag!=))//循环只剩下一个人时结束
{
for(int i=;i<len;i++)
{
if(arr[i]==) continue;
if(arr[i]%==)
{
arr[i]=arr[i]/;
}
else
{
if(i==len-)
arr[i]=arr[i]/;
else
{
arr[i]=arr[i]/;
arr[i+]+=;
}
}
}
for(int i=; i<=; i++)//完全套用大数阶乘的代码
{
for(int j=; j<=m; j++)
num[j]=num[j]*i;
for(int k=; k<=m; k++)
{
num[k]+=num[k-]/;
num[k-]=num[k-]%;//注意和上一个的顺序
}
while(num[m]>)
{
num[m+]=num[m]/;
num[m]%=;
m++;
}
}
flag=;
for(int i=;i<len-;i++)
{
if(arr[i]!=)
flag=;
}
}
for(int i=m; i>=; i--)
printf("%d",num[i]);
printf("\n");
}
return ;
}

2082 : Only choose one的更多相关文章

  1. Mybatis的choose when otherwise

    <select id="getCount" resultType="int"> select count(1) from <choose> ...

  2. mybatis:choose when otherwise标签

    choose标签是按顺序判断其内部when标签中的test条件是否成立,如果有一个成立,则 choose 结束. 当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的 ...

  3. 理解 OpenStack + Ceph (9): Ceph 的size/min_size/choose/chooseleaf/scrubbing/repair 等概念

    本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...

  4. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  5. jstl catch if choose标签

    catch标签: catch标签用来处理异常 属性: * var :用来出现异常保存到的变量. 代码: <c:catch var="e"> <% int i = ...

  6. uva10375 Choose and Divide(唯一分解定理)

    uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...

  7. 升级到macos sierra xcode8 requires additional components to support runing and debugging choose Install to add required components

    升级到macos sierra xcode8 报提示:requires additional components to support runing and debugging choose Ins ...

  8. FZU Problem 2082 过路费 树链剖分

    Problem 2082 过路费    Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新, ...

  9. Choose Concurrency-Friendly Data Structures

    What is a high-performance data structure? To answer that question, we're used to applying normal co ...

随机推荐

  1. [Err] 1093 - You can't specify target table 'master_data' for update in FROM clause

    delete from master_data where category_id not in (select category_id from master_data a, bc_category ...

  2. git 仓库原理

    Git 版本控制原理 标签: git 版本控制 版本回退 2017年01月13日 21:07:202399人阅读 评论(0) 收藏 举报  分类: Git(4)  版权声明:本文为博主原创文章,未经博 ...

  3. myBatis简学

    mybatis使用: ①拷贝相关mybits ②编写对象关系映射,一般都是实体类名+Mapper.xml的格式 ③编写mybits配置文件: a)配置环境 b)配置映射文件地址 ④编写对象操作方法: ...

  4. 一般处理程序、Ajax多图片上传带进度条

    <!DOCTYPE html><html><head>    <meta charset="utf-8" />    <tit ...

  5. 复杂xml格式报文和实体类之间的转化

    pom.xml中引入如下依赖: <dependency> <groupId>org.eclipse.persistence</groupId> <artifa ...

  6. https://www.cnblogs.com/h2zZhou/p/5440271.html

    https://www.cnblogs.com/h2zZhou/p/5440271.html

  7. 使用Maps与Sets处理集合的交差运算

    import com.google.common.collect.MapDifference; import com.google.common.collect.Maps; import java.u ...

  8. 【Shell】单行注释和多行注释

    单行注释 '# ' # echo "hello" 多行注释 方法1 : << ! 这是注释1 这是注释2 这是注释3 ! 方法2 :' 这是注释1 这是注释2 这是注释 ...

  9. jsp页面传中文到后台乱码怎么办?

    一般从前台传值到后腰如果传的值是中文的话,又不用post传值方式,到后台显示会显示成乱码的形式.所以以下方法亲测有效防止乱码. 前台jsp页面: var taskTitle = $('#taskTit ...

  10. shell练习题7

    需求如下: 输入一串随机数字,然后按千分位输出. 例如:输入随机数字为"123456789",输出为123,456,789 参考解答如下 -方法1 [root@lanquark s ...