题目描述

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 1.
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?

输入

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 ≤ 1050 .

输出

The output displays t lines, each containing a single integer which is the place where you would stand to win the chance.

样例输入

4
5
12
23
35

样例输出

4
8
16
32
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct bign{
int d[maxn], len;
void clean() { while(len > && !d[len-]) len--; }
bign() { memset(d, , sizeof(d)); len = ; }
bign(int num) { *this = num; }
bign(char* num) { *this = num; }
bign operator = (const char* num){
memset(d, , sizeof(d)); len = strlen(num);
for(int i = ; i < len; i++) d[i] = num[len--i] - '';
clean();
return *this;
}
bign operator = (int num){
char s[]; sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator + (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] += b.d[i];
if (c.d[i] > ) c.d[i]%=, c.d[i+]++;
}
while (c.d[i] > ) c.d[i++]%=, c.d[i]++;
c.len = max(len, b.len);
if (c.d[i] && c.len <= i) c.len = i+;
return c;
}
bign operator - (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] -= b.d[i];
if (c.d[i] < ) c.d[i]+=, c.d[i+]--;
}
while (c.d[i] < ) c.d[i++]+=, c.d[i]--;
c.clean();
return c;
}
bign operator * (const bign& b)const{
int i, j; bign c; c.len = len + b.len;
for(j = ; j < b.len; j++) for(i = ; i < len; i++)
c.d[i+j] += d[i] * b.d[j];
for(i = ; i < c.len-; i++)
c.d[i+] += c.d[i]/, c.d[i] %= ;
c.clean();
return c;
}
bign operator / (const bign& b){
int i, j;
bign c = *this, a = ;
for (i = len - ; i >= ; i--)
{
a = a* + d[i];
for (j = ; j < ; j++) if (a < b*(j+)) break;
c.d[i] = j;
a = a - b*j;
}
c.clean();
return c;
}
bign operator % (const bign& b){
int i, j;
bign a = ;
for (i = len - ; i >= ; i--)
{
a = a* + d[i];
for (j = ; j < ; j++) if (a < b*(j+)) break;
a = a - b*j;
}
return a;
}
bign operator += (const bign& b){
*this = *this + b;
return *this;
} bool operator <(const bign& b) const{
if(len != b.len) return len < b.len;
for(int i = len-; i >= ; i--)
if(d[i] != b.d[i]) return d[i] < b.d[i];
return false;
}
bool operator >(const bign& b) const{return b < *this;}
bool operator<=(const bign& b) const{return !(b < *this);}
bool operator>=(const bign& b) const{return !(*this < b);}
bool operator!=(const bign& b) const{return b < *this || *this < b;}
bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);}
string str() const{
char s[maxn]={};
for(int i = ; i < len; i++) s[len--i] = d[i]+'';
return s;
}
};
istream& operator >> (istream& in, bign& x)
{
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream& out, const bign& x)
{
out << x.str();
return out;
}
int main()
{
int TTT;
cin>>TTT;
while(TTT--)
{
bign a,b,c;
c=;
cin>>a;
b=;
while(b<a) b=b*c;
if(b==a) cout<<b<<endl;
else{
b=b/c;
cout<<b<<endl;
}
}
return ;
}

题目不难理解,看样例的特点就知道了

然后那个高精度模板

虽然多

但是用起来不费劲。。。。

The Chosen One+高精度的更多相关文章

  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. 高精度乘法-17南宁区域赛F -The Chosen One

    题目大意:给你一个n,然后从1~n隔一个选一个,挑出一个集合然后从集合中继续隔一个挑一个,直到只有一个数,问最后一个数是多少?2<=n<=1050 例如n=5,先选出2,4最后选择4.n= ...

  3. CSharpGL(28)得到高精度可定制字形贴图的极简方法

    CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...

  4. 递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)

    题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个 ...

  5. [Template]高精度模板

    重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...

  6. jQuery下拉框扩展和美化插件Chosen

    Chosen 是一个支持jquery的select下拉框美化插件,它能让丑陋的.很长的select选择框变的更好看.更方便.不仅如此,它更扩展了select,增加了自动筛选的功能.它可对列表进行分组, ...

  7. Code[VS] 3123 高精度练习之超大整数乘法

    FFT 做 高精度乘法 #include <bits/stdc++.h> ); struct complex { double a, b; inline complex( , ) { a ...

  8. Java 高精度数字

    BigInteger // 高精度整数 BigDecimal //高精度小数  小数位数不受限制

  9. c++减法高精度算法

    c++高精度算法,对于新手来说还是一大挑战,只要克服它,你就开启了编程的新篇章,算法. 我发的这个代码并不是很好,占用内存很多而且运行时间很长(不超过0.02秒),但是很好理解,很适合新手 高精算法的 ...

随机推荐

  1. eclipse导入tomcat源码

    我的开发环境:windows7  64位 一.官网下载tomcat源码.在此奉上一站地址:http://archive.apache.org/dist/tomcat/: 二.编译源码生成.jar文件: ...

  2. 题解 P4781 【【模板】拉格朗日插值】

    题目 本蒟蒻看到一道数学题,就顺手切了.感觉单单对这一题而言,部分评论区的大佬过于复杂了 [分析] 先讲讲拉格朗日插值法: 对于给定的 \((n+1)\) 个点,我们可以确定唯一的一个 至多\(n\) ...

  3. 吴裕雄--天生自然 JAVASCRIPT开发学习:Window - 浏览器对象模型

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. Maven--部署构件至 Nexus

    日常开发生成的快照版本构件可以直接部署到 Nexus 中策略为 Snapshot 的宿主仓库中,项目正式发布的构件则应该部署到 Nexus 中策略为 Release 的宿主仓库中. <proje ...

  5. String,StringBuffer与StringBuilder的区别与选择

    三者的区别 String:不可变类,一旦一个对象被建立的时候,包含在这个对象中的字符串序列是不可变的,直到这个对象被销毁.StringBuffer:可变字符序列的字符串.当其对象被创建的时候,可以用a ...

  6. Java Keyword Static 学习记录

    Static Java编程思想:一旦将什么东西设为static,数据或方法就不会同那个类的任何对象实例联系到一起. 特点:随着类的加载而加载,随着类的销毁而销毁. 作用:可以修饰成员变量,代码块,方法 ...

  7. 字符串中子序列出现次数(dp)

    躲藏 链接:https://ac.nowcoder.com/acm/problem/15669来源:牛客网 题目描述 XHRlyb和她的小伙伴Cwbc在玩捉迷藏游戏. Cwbc藏在多个不区分大小写的字 ...

  8. react-native屏幕适配

    写一个屏幕适配类文件AdapterUtil.js,这样避免每次进行单位换算 "use strict" import {Dimensions, StatusBar, Platform ...

  9. 添加并启动MySQL服务

    1. 右键开始菜单,选择 2. 进入到MySQL安装目录下的bin目录,输入命令: mysqld.exe -install 3.启动mysql服务,输入命令: net start mysql

  10. DispatcherServlet和ContextLoaderListener,还有spring+servlet3.0 无web.xml启动问题

    上篇提到: 关于spring +springmvc中两个spring应用上下文(DispatcherServlet和ContextLoaderListener)的问题,挺让人迷糊的. 他们都是加载Be ...