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;
}
}
}
}

最新文章

  1. Tomcat7配置及其servlet调用详解
  2. 使用dnsmasq来提升CentOS上网速度
  3. 基于HTML5技术的电力3D监控应用(三)
  4. 关于修改tabbar的颜色的问题
  5. 【刷题 Python Tip】题目6~10
  6. 03-UIKit、VC之间正向反向传值、代理
  7. JDK、Eclipse、Myeclipse、Tomcat等各种软件的版本详解(写给对版本和兼容性问题焦头烂额的你)
  8. 201521123072《Java程序设计》第1周学习总结
  9. windows之自动化在虚拟机部署操作系统并自带python环境
  10. HDOJ5543 Pick The Sticks
  11. UVA1618-Weak Key(RMQ)
  12. 微软官方的Windowsphone社区
  13. ECharts柱状图添加点击事件
  14. oracle数据库连接池查看
  15. 20155314 2016-2017-2 《Java程序设计》实验四 Android程序设计
  16. 【docker】关于docker中挂载的解释
  17. C#(winform)为button添加背景图片,并去掉各种边框
  18. Unix网络编程 3.9 readline函数
  19. Oracle 常用脚本
  20. python3 简单爬虫

热门文章

  1. LINUX学习之一基础篇
  2. 【Wince-DataTable填充ListView】DataTable的数据填充到ListView控件,适用.Net2.0
  3. vs2017 mvc 自定义路由规则 出现 404.0 错误代码 0x80070002
  4. k8s命令自动补全
  5. .net core 下载文件 其他格式
  6. C# image/byte[]/string/互转
  7. List集合的三个实现类比较
  8. 计算机网络(五),TCP四次挥手
  9. python解析字体反爬
  10. AtCoder4351 Median of Medians 二分, 树状数组