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次幂)的更多相关文章

  1. ICPC Asia Nanning 2017 F. The Chosen One (高精度运算)

    题目链接:The Chosen One 比赛链接:ICPC Asia Nanning 2017 题意 \(t\) 组样例,每组给出一个整数 \(n(2\le n\le 10^{50})\),求不大于 ...

  2. ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)

    题目链接:Twice Equation 比赛链接:ICPC Asia Nanning 2017 Description For given \(L\), find the smallest \(n\) ...

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

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

  5. 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位 最大值为 ...

  6. The Preliminary Contest for ICPC Asia Shenyang 2019 F. Honk's pool

    题目链接:https://nanti.jisuanke.com/t/41406 思路:如果k的天数足够大,那么所有水池一定会趋于两种情况: ① 所有水池都是一样的水位,即平均水位 ② 最高水位的水池和 ...

  7. 17 南宁区域赛 F - The Chosen One 【规律】

    题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...

  8. 2019 ICPC Asia Nanchang Regional C And and Pair 找规律/位运算/dp

    题意: 给定一个二进制表示的n,让你找满足如下要求的数对(i,j)的个数 $0 \leqslant j \leqslant i \leqslant n$ $ i & n = i $ $ i & ...

  9. 【2021 ICPC Asia Jinan 区域赛】 C Optimal Strategy推公式-组合数-逆元快速幂

    题目链接 题目详情 (pintia.cn) 题目 题意 有n个物品在他们面前,编号从1自n.两人轮流移走物品.在移动中,玩家选择未被拿走的物品并将其拿走.当所有物品被拿走时,游戏就结束了.任何一个玩家 ...

随机推荐

  1. zTree 节点展开

    var treeObj = $("#treeDemo"); $.fn.zTree.init(treeObj, setting, Znode1); zTree_Menu = $.fn ...

  2. 直接选择排序(Straight Selection Sort)

    1.定义 选择排序(Selection Sort)的基本思想是:每一趟从待排序的记录中选出关键字最小的记录,顺序放在已排好序的子文件的最后,直到全部记录排序完毕. 常用的选择排序方法有直接选择排序和堆 ...

  3. 八、定制new和delete

    条款49:了解new-handler的行为 new异常会发生什么事? 在旧式的编译器中,operator new分配内存失败的时候,会返回一个null指针.而现在则是会抛出一个异常. 而在抛出这个异常 ...

  4. Springboot(九).多文件上传下载文件(并将url存入数据库表中)

    一.   文件上传 这里我们使用request.getSession().getServletContext().getRealPath("/static")的方式来设置文件的存储 ...

  5. TC-SRM391-div2-SortingGame(BFS,STL)

    Problem Statement for SortingGame Problem Statement In The Sorting Game, you are given a sequence co ...

  6. MySQ彻底删除与安装配置

    彻底删除 1.查看 MySQL 安装了哪些东西 rpm -qa |grep -i mysql 2.卸载 -.el7.x86_64 -.el7.x86_64 .noarch -.el7.x86_64 - ...

  7. Java缓存技术有哪些

    我们用ehcache在本地,分布式用redis和memcache,各有各的好处,现在企业都是应用很多种中间件供俺们码农选择.

  8. readyState xhr对象当前状态

    var request=new XMLHttpRequest(); request.open("GET","get.php",true); request.se ...

  9. linux下快速查找文件(转载)

    权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/xxmonstor/article/deta ...

  10. Adding property to a json object in C#

    Adding property to a json object in C#   you can do it with a dynamic object dynamic obj = JsonConve ...