ICPC Asia Nanning 2017 F. The Chosen One (大数、规律、2的k次幂)
Welcome to the 2017 ACM-ICPC Asia Nanning Regional Contest.
Here is a breaking news. Now you have a chance to meet alone with the Asia Director through a game.
All boys and girls who chase their dreams have to stand in a line. They are given the numbers in the order in which they stand starting from 111.
The host then removes all boys and girls that are standing at an odd position with several rounds.
For example if there are n=8 boys and girls in total. Initially standing people have numbers 1,2,3,4,5,6,7 and 8. After the first round, people left are 2,4,6 and 8. After the second round, only two people, 4 and 8, are still there.
The one who stays until the end is the chosen one.
I know you want to become the chosen one to meet alone with your idol. Given the number of boys and girls in total, can you find the best place to stand in the line so that you would become the chosen one?
Input
First line of the input contains the number of test cases t(1≤t≤1000)
Each of the next t lines contains the integer n which is the number of boys and girls in total, where 2≤n≤10^50
Output
The output displays t lines, each containing a single integer which is the place where you would stand to win the chance.
题目大意
有n个小孩排成一排,每次除去站在奇数位置上的小孩,问最后剩下哪一个
题目分析
多模拟几遍就会发现,剩下的是小于n的2的最大次幂 比如n=17时就是16,35时就是32.....
剩下的就是对大数的处理了,不会java,所以写了C++...
代码
#include <bits/stdc++.h> using namespace std; char anss[][],temp[][];
int jin=,cnt=,i,j,t,lang[]; int main()
{
anss[][]='';
for(i=;i<=;i++)
{
for(j=;j<=cnt;j++)
{
//cout<<(anss[i-1][j]-'0'+jin)*2+'0'<<endl;
anss[i][j]=((anss[i-][j]-'')*+jin)%+'';
jin=((anss[i-][j]-'')*+jin)/;
}
//cout<<jin<<endl;
while(jin)
{
//cout<<jin<<endl;
anss[i][++cnt]=jin%+'';
jin=jin/;
//cout<<jin<<endl;
}
lang[i]=cnt;
//cout<<anss[i]<<endl;
}
for(i=;i<=;i++)
{
for(j=lang[i];j>=;j--)
{
temp[i][lang[i]-j]=anss[i][j];
}
//cout<<temp[i]<<endl;
}
cin>>t;
while(t--)
{
char str[];
cin>>str;
//cout<<strlen(str)<<endl;
for(i=;i<;i++)
{
int flag1=;
int flag2=;
if(strlen(str)<lang[i+]+)
{
cout<<temp[i]<<endl;
break;
}
if(strlen(str)>lang[i]+&&strlen(str)==lang[i+]+)
{
if(strcmp(temp[i+],str)>)
{
cout<<temp[i]<<endl;
break;
}
}
if(strlen(str)==lang[i]+&&strlen(str)==lang[i+]+)
if(strcmp(temp[i],str)<=&&strcmp(temp[i+],str)>)
{
cout<<temp[i]<<endl;
break;
}
}
}
}
ICPC Asia Nanning 2017 F. The Chosen One (大数、规律、2的k次幂)的更多相关文章
- ICPC Asia Nanning 2017 F. The Chosen One (高精度运算)
题目链接:The Chosen One 比赛链接:ICPC Asia Nanning 2017 题意 \(t\) 组样例,每组给出一个整数 \(n(2\le n\le 10^{50})\),求不大于 ...
- ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)
题目链接:Twice Equation 比赛链接:ICPC Asia Nanning 2017 Description For given \(L\), find the smallest \(n\) ...
- ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)
题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...
- 2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198【矩阵快速幂】
Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 F. Rhyme scheme(dp)
题意:给你一个n和k 要你找到长度为n 字典序第k小的字符串 定义一个字符串合法:第i的字符的范围只能是前i-1个字符中的最大值+1 思路:我们dp[n][i][j]表示长度为n 在第i位 最大值为 ...
- The Preliminary Contest for ICPC Asia Shenyang 2019 F. Honk's pool
题目链接:https://nanti.jisuanke.com/t/41406 思路:如果k的天数足够大,那么所有水池一定会趋于两种情况: ① 所有水池都是一样的水位,即平均水位 ② 最高水位的水池和 ...
- 17 南宁区域赛 F - The Chosen One 【规律】
题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...
- 2019 ICPC Asia Nanchang Regional C And and Pair 找规律/位运算/dp
题意: 给定一个二进制表示的n,让你找满足如下要求的数对(i,j)的个数 $0 \leqslant j \leqslant i \leqslant n$ $ i & n = i $ $ i & ...
- 【2021 ICPC Asia Jinan 区域赛】 C Optimal Strategy推公式-组合数-逆元快速幂
题目链接 题目详情 (pintia.cn) 题目 题意 有n个物品在他们面前,编号从1自n.两人轮流移走物品.在移动中,玩家选择未被拿走的物品并将其拿走.当所有物品被拿走时,游戏就结束了.任何一个玩家 ...
随机推荐
- C# 2.0
序言 泛型 为什么需要泛型? 分部类型 分部类和方法 partial 匿名方法 使用Delegate的时候很多时候没必要使用一个普通的方法,因为这个方法只有这个Delegate会用,并且只用一次,这时 ...
- SpringBoot项目中,异常拦截
SpringBoot自带异常拦截@ControllerAdvice 1.创建一个SellerExceptionHandler类打上@ControllerAdvice标签 @ControllerAdvi ...
- mysql 日期转换sql函数
mysql提供了两个函数: from_unixtime(time_stamp) -> 将时间戳转换为日期 unix_timestamp(date) -> 将 ...
- JavaWeb_JSTL标签数据的存储
菜鸟教程 传送门 JSTL jar包下载 JSTL[百度百科]:(JavaServer Pages Standard Tag Library,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库 ...
- HTML jQuery 文档操作 - html() 方法
jQuery 文档操作 - html() 方法 jQuery 文档操作参考手册 实例 设置所有 p 元素的内容: $(".btn1").click(function(){ $(&q ...
- 消息队列rabbitmq/kafka
12.1 rabbitMQ 1. 你了解的消息队列 rabbitmq是一个消息代理,它接收和转发消息,可以理解为是生活的邮局.你可以将邮件放在邮箱里,你可以确定有邮递员会发送邮件给收件人.概括:rab ...
- MySQL + centos +主从复制
MYSQL(mariadb) MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的 ...
- Hibernate理解?
(1)Hibernate是对象关系映射框架,对JDBC进行非常轻量级的对象封装,是全自动的ORM框架,可以自动生成SQL语句.自动执行. (2)语言特点 <1>将对数据库的操作转换为对Ja ...
- jsvnadmin访问一直登陆 找不到用户
报错:AH01618: user zhangsan not found: /svn/hangzhi 在svnadmin控制台上将用户分好组,不然即使有账户也登不上
- LeetCode 40. 组合总和 II(Combination Sum II)
题目描述 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的每个数字在每个组合中只能 ...