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. vue-router嵌套路由,二级路由。

    如果全是用一级路由时,路由管理就变得很臃肿,有点乱,路由有父子关系的话,嵌套路由会更好.嵌套也就是路由中的路由的意思,组件中可以有自己的路由导航和路由容器(router-link.router-vie ...

  2. C# Stopwatch 延时

    using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading ...

  3. Python 文件I/O Ⅳ

    Python里的目录: 所有文件都包含在各个不同的目录下,不过Python也能轻松处理.os模块http://www.xuanhe.net/有许多方法能帮你创建,删除和更改目录. mkdir()方法 ...

  4. UML中的类图及类图之间的关系

    统一建模语言简介 统一建模语言(Unified Modeling Language,UML)是用来设计软件蓝图的可视化建模语言,1997 年被国际对象管理组织(OMG)采纳为面向对象的建模语言的国际标 ...

  5. 什么是CSS 表单?

    ㈠输入框(input) 样式 ⑴使用 width 属性来设置输入框的宽度   示例:css部分:input { width: 100%; }                html部分:<for ...

  6. head first 设计模式笔记9-迭代器模式

    迭代器模式:提供一种方法顺序访问一个集合对象中的各个元素,而又不暴露其内部的表示. 迭代器接口 /** * @author oy * @date 2019年9月22日 上午9:03:08 * @ver ...

  7. Eclipse中注释乱码解决办法

    问题描述:将别人的Java工程导入自己的工作空间之后,有时候会出现注释乱码问题. 这是由于IDE对汉字的编码方式不同造成的.比如,原来的开发人员使用的是UTF-8编码方式,而现在开发人员使用的IDE使 ...

  8. java知识查漏补缺

    一.重写(override)和重载(overload)的区别 二者除了名字相似,其实没什么联系 范围不同:重载发生在同一个类的不同方法之间.重写发生在父类和子类自荐. 前提: 重载要求:方法名相同,参 ...

  9. 使用R进行方差分析

    eff=c(58.2,52.6,56.2,41.2,65.3,60.8,49.1,42.8,54.1,50.5,51.6,48.4,60.1,58.3,70.9,73.2,39.2,40.7,75.8 ...

  10. 分布式-网络通信-IO-基础(1)

    IO整体图架构  一.IO流概述 概述: IO流简单来说就是Input和Output流,IO流主要是用来处理设备之间的数据传输,Java对于数据的操作都是通过流实现,而java用于操作流的对象都在IO ...