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 ...
随机推荐
- Tensorflow(添加噪声的方式)
在去噪自编码器中,模型的输入是原始的输入经过某种形式的加噪过程后的衰弱的形式,所以加噪声一般分为:加高斯白噪声,掩模噪声,椒盐噪声. 1.加性高斯噪声 self.scale = tf,placehol ...
- keeplived
keepalived高可用集群. keepalived故障切换转移原理1vrrp协议:(vritual router redundancy protocol)虚拟路由冗余协议,2故障转移.keep ...
- Ehlib 学习
似乎是为了垂直滚动条 SumList.Active := True; SumList.VirtualRecords := True; TDBGridEh 设计时 It is useful to use ...
- jvm参数及分析工具
-Xmx4G 设置堆的最大内存大小为4GB,也可通过-XX:MaxHeapSize=4GB进行设置 -Xms256m 设置堆的初始内存大小为256兆,如果未设置此选项,则初始大小将设置为新生代和年老代 ...
- Linux 下编程
关于Linux 下的C语言编译命令和编程要点! https://www.cnblogs.com/wfwenchao/p/3985153.html?utm_source=tuicool&utm_ ...
- 查询总耗CPU最多与平均耗CPU最多的SQL语句
总耗CPU最多的前20个SQL total_worker_time AS [总消耗CPU 时间(ms)],execution_count [运行次数], qs.total_worker_time AS ...
- js获取元素属性值为空的原因和解决办法
问题描述:js获取某元素的属性值为空 代码: <!-- css定义在head中 --> <style> #box{ width: 100px; height: 100px; b ...
- Eclipse个人快捷键设置及常用快捷键
Eclipse中字母自动提示的快捷键设置,具体如下图所示,加上大写字母A-Z 二.常用快捷键设置 (1)在java代码中按 ctrl+O 快速查看类的属性和方法列表如下所示 (2)在java代码中选中 ...
- C# 温故之.NET 异步
Bitter Coffee的温故之.NET 异步 相当经典(请允许我用经典两字),读了好几遍,留存.
- nginx申请并配置免费https
你还在让你的网站裸奔在网络上吗?在这里我们将搭建免费版HTTPS,免费的,免费的,免费的,重要的事情说三遍,申请来源为letsencrypt, 超文本传输协议HTTP协议被用于在Web浏览器和网站服务 ...