2082 : Only choose one
题目描述
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的更多相关文章
- Mybatis的choose when otherwise
<select id="getCount" resultType="int"> select count(1) from <choose> ...
- mybatis:choose when otherwise标签
choose标签是按顺序判断其内部when标签中的test条件是否成立,如果有一个成立,则 choose 结束. 当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的 ...
- 理解 OpenStack + Ceph (9): Ceph 的size/min_size/choose/chooseleaf/scrubbing/repair 等概念
本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- jstl catch if choose标签
catch标签: catch标签用来处理异常 属性: * var :用来出现异常保存到的变量. 代码: <c:catch var="e"> <% int i = ...
- 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 ...
- 升级到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 ...
- FZU Problem 2082 过路费 树链剖分
Problem 2082 过路费 Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新, ...
- Choose Concurrency-Friendly Data Structures
What is a high-performance data structure? To answer that question, we're used to applying normal co ...
随机推荐
- day27_python_1124
1.内容回顾 2.今日内容 3.创建-进程Process 4.join方法 5.进程之间数据隔离 1.内容回顾 # 进程 :是计算机中最小的资源分配单位# 进程的三状态 :就绪 运行 阻塞# 并发和并 ...
- 修改 input中的placeholder的字体样式和颜色
placeholder属性是css3中新增加的属性, 由于是新加入的属性因此对各大浏览器都不兼容: 因此在使用的时候要加兼容性 火狐:-moz-placeholder { /* Mozilla Fir ...
- win10 adb(Android Debug Bridge)导出日志
百度了一下 各种设置环境变量.放到system32文件夹(64位系♂统放到C:\Windows\SysWOW64)等 公司电脑win10系统 方便多了 把环境变量设置啥的全删了 adb下载地址:htt ...
- Unity中用Mono插件解析xml文件
1.解压压缩包,把文件夹拖到脚本文件夹下 Mono是第三方基金会开发的开源的东西,通过Mono基础上开发的程序可以在各个系统下运行.开发语言是C#. 用插件解析比较高效,平台运行稳定.使用简单. Un ...
- springboot 多端口启动
以eclipse(STS)为例, 选中项目右键Run Configurations 点击Spring Boot App,选中需要设定多端口项目,在启动参数一栏输入:-Dserver.port=7003 ...
- win10 安装mysql 8.0.12
按照CSDN以及博客园的其他教程, 之前安装过几次都有或多或少的bug 主要安装步骤: 1.配置my.ini文件 2.管理员进入终端, 切换到.../bin目录下进行操作 3.指令操作: 1) mys ...
- C语言:递归函数n!
#include <stdio.h> long recursion(int n); void main(){ int n; long result; printf("input ...
- MySQL行转列、列转行
一.行转列 有如图所示的表,现在希望查询的结果将行转成列 建表语句如下: CREATE TABLE `TEST_TB_GRADE` ( `ID` int(10) NOT NULL AUTO_INCRE ...
- JS--------文件操作基本方法:上传/下载
/** * 上传文件 * @param {any} files 文件 * @param {any} data 数据 * @returns [true,文件路径] * @returns [false,异 ...
- 了解box-sizing 盒子模型
最近看到别人代码有用到box-sizing属性,自己没用过,记录一下 box-sizing:border-box 指定宽度和高度(最小/最大属性)确定元素边框box 理解:假设宽高为100px,设置了 ...