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.两人轮流移走物品.在移动中,玩家选择未被拿走的物品并将其拿走.当所有物品被拿走时,游戏就结束了.任何一个玩家 ...
随机推荐
- 性能优化(1+N,list与iterator,缓存,事务)
1.注意session.clear()的运用,尤其是不断分页循环的时候 A 在一个大集合中进行遍历,取出其中含有敏感字的对象 B 另一种形式的内存泄露. 2.1+N问题 问题描述:如@ManyToOn ...
- 【51nod1792】Jabby's segment tree
题目 线段树是一种经典的数据结构,一颗[1,n]的线段树他的根是[1,n],当一个线段树的结点是[l,r]时,设mid=(l+r)>>1,则这个结点的左儿子右儿子分别是[l,mid],[m ...
- 微信小程序没找到构建npm或者没找到node_modules目录以及如何在小程序中引入vant weapp组件
微信小程序没找到构建npm或者没找到node_modules目录解决方法如下: 按照微信小程序提供的文档npm install是不行的,直接提示没找到可构建的npm包. 1.直接安装:npm init ...
- centos 修改时区以及修正时间
1.查看系统当前的时区 [app@127-0-0-1 shine]$ timedatectl Local time: Wed 2019-10-23 17:56:17 CST Universal tim ...
- Jmeter(一) 安装
一.检查JDK版本 执行cmd > java -version 查看本机JDK版本,JDK版本不能低于1.6 二.软件下载 登录Jmeter官网:https://jmeter.apache.or ...
- 解决新建Maven项目webapp-- index.jsp报错
现在,随着项目开发的不断增长,项目变得庞大,jar包管理起来也很费时.使用maven工程可以很轻松的帮助我们管理jar包,省时. 今天,我在公司电脑新建的maven工程,新建完后 index.jsp报 ...
- mybatis逆向工程的text类型的一个小坑
数据库如果配有text的数据类型的 mybatis生成逆向工程的时候会单独将text提取出来 ByExampleWithBLOBs 会生成上面后缀的查询和修改的语句 因此查询起来会产生没有必要的麻烦, ...
- C语言中的!!
C语言中!!的作用是?看例子: #include <stdio.h> int main() { ; printf("test=%d !test=%d !!test=%d\n&qu ...
- C# 下载文件的心得
下载文件最常用的有两种: 第一种:直接使用A标签,对应着文件的地址. 第二种:将文件写成流,然后在回传给客户端. 第一种,使用起来方便,但是有个坏处,如果你的文件是可编辑的文件(比如Excel wor ...
- Macpro搭建java自动化(selenium+chrome)
准备工作: 1.下载安装eclipse,并安装培训jdk软件及环境变量: 2.下载selenium,系工具包: http://seleniumhq.org/download/ selenium-ser ...