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. python查询mysql数据(3)

    python查询mysql数据(3) """数据查询""" import pymysql import datetime from pymy ...

  2. python读取文件出现\ufeff问题

    现象: 读取csv文件,表头为'ID',但读取后显示'\ufeffID',所以使用dict['ID']读取会报错 原因: 该文件保存时保存了BOM,保存于文件头部 解决: 将原有的 file_cont ...

  3. electron桌面通知,修改默认通知应用名electron.app.Electron为自己应用的名称

    在做electron桌面通知时,按照文档实现弹出通知,但是默认的应用名为electron.app.Electron 解决办法 就是在主进程中设置 app.setAppUserModelId('myAp ...

  4. Golang闭包和匿名函数

    1. 匿名函数 匿名函数就是没有函数名的函数,如下所示. func test() int { max := func(a, b int) int { if a > b { return a } ...

  5. HTML新手入门(1)

    HTML新手入门(1) ——编译器下载及基础框架 一.编译器下载 作为新手,听取大佬的建议,用HBuilder进行编译. 下载地址:www.dcloud.io/ 进入到首页左上角有一个如下图标. (这 ...

  6. 【杂题】[AGC034D] Manhattan Max Matching【费用流】

    Description 有一个无限大的平面,有2N个位置上面有若干个球(可能重复),其中N个位置是红球,N个位置是蓝球,红球与蓝球的总数均为S. 给出2N个位置和上面的球数,现要将红球与蓝球完美匹配, ...

  7. [CSP-S模拟测试]:统计(树状数组+乱搞)

    题目传送门(内部题120) 输入格式 第一行,两个正整数$n,m$. 第二行,$n$个正整数$a_1,a_2,...,a_n$,保证$1\leqslant a_i\leqslant n$,可能存在相同 ...

  8. C++入门经典-例6.6-字符串复制

    1:字符串复制函数strcpy的格式如下: strcpy(字符数组名,字符串) 其作用是把字符串中的字符串复制到字符数组中.需要注意的是,字符串结束标志'\0'也一同被复制. 注意是将后面的内容复制给 ...

  9. IDEA无法自动导入HttpServlet包问题解决

    全部都报红,连Alt + Enter都没有提示导包 这时候只需要IDEA右上角的这个键 再点击Libraries 选择添加 → Java 再把你Tomcat中对应的servlet-api.jar添加进 ...

  10. Java期末课程学习汇总。

    本学期面向对象与Java程序设计课程已经结束了,给自己学习来个总结. 本学期过的非常快,不得不说这一学期学到的东西很少,感觉自己的进步很小. 而且感觉自己总少了点什么,在写这篇总结前,我认真想了,很多 ...