The Chosen One+高精度

题目描述

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 ≤ 10 50 .

输出

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
  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const int maxn = 1000;
  4 struct bign{
  5     int d[maxn], len;
  6     void clean() { while(len > 1 && !d[len-1]) len--; }
  7     bign()          { memset(d, 0, sizeof(d)); len = 1; }
  8     bign(int num)   { *this = num; }
  9     bign(char* num) { *this = num; }
 10     bign operator = (const char* num){
 11         memset(d, 0, sizeof(d)); len = strlen(num);
 12         for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0';
 13         clean();
 14         return *this;
 15     }
 16     bign operator = (int num){
 17         char s[20]; sprintf(s, "%d", num);
 18         *this = s;
 19         return *this;
 20     }
 21     bign operator + (const bign& b){
 22         bign c = *this; int i;
 23         for (i = 0; i < b.len; i++){
 24             c.d[i] += b.d[i];
 25             if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++;
 26         }
 27         while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++;
 28         c.len = max(len, b.len);
 29         if (c.d[i] && c.len <= i) c.len = i+1;
 30         return c;
 31     }
 32     bign operator - (const bign& b){
 33         bign c = *this; int i;
 34         for (i = 0; i < b.len; i++){
 35             c.d[i] -= b.d[i];
 36             if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--;
 37         }
 38         while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--;
 39         c.clean();
 40         return c;
 41     }
 42     bign operator * (const bign& b)const{
 43         int i, j; bign c; c.len = len + b.len;
 44         for(j = 0; j < b.len; j++) for(i = 0; i < len; i++)
 45             c.d[i+j] += d[i] * b.d[j];
 46         for(i = 0; i < c.len-1; i++)
 47             c.d[i+1] += c.d[i]/10, c.d[i] %= 10;
 48         c.clean();
 49         return c;
 50     }
 51     bign operator / (const bign& b){
 52         int i, j;
 53         bign c = *this, a = 0;
 54         for (i = len - 1; i >= 0; i--)
 55         {
 56             a = a*10 + d[i];
 57             for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
 58             c.d[i] = j;
 59             a = a - b*j;
 60         }
 61         c.clean();
 62         return c;
 63     }
 64     bign operator % (const bign& b){
 65         int i, j;
 66         bign a = 0;
 67         for (i = len - 1; i >= 0; i--)
 68         {
 69             a = a*10 + d[i];
 70             for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
 71             a = a - b*j;
 72         }
 73         return a;
 74     }
 75     bign operator += (const bign& b){
 76         *this = *this + b;
 77         return *this;
 78     }
 79 
 80     bool operator <(const bign& b) const{
 81         if(len != b.len) return len < b.len;
 82         for(int i = len-1; i >= 0; i--)
 83             if(d[i] != b.d[i]) return d[i] < b.d[i];
 84         return false;
 85     }
 86     bool operator >(const bign& b) const{return b < *this;}
 87     bool operator<=(const bign& b) const{return !(b < *this);}
 88     bool operator>=(const bign& b) const{return !(*this < b);}
 89     bool operator!=(const bign& b) const{return b < *this || *this < b;}
 90     bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);}
 91     string str() const{
 92         char s[maxn]={};
 93         for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0';
 94         return s;
 95     }
 96 };
 97 istream& operator >> (istream& in, bign& x)
 98 {
 99     string s;
100     in >> s;
101     x = s.c_str();
102     return in;
103 }
104 ostream& operator << (ostream& out, const bign& x)
105 {
106     out << x.str();
107     return out;
108 }
109 int main()
110 {
111     int TTT;
112     cin>>TTT;
113     while(TTT--)
114     {
115         bign a,b,c;
116         c=2;
117         cin>>a;
118         b=1;
119         while(b<a) b=b*c;
120         if(b==a) cout<<b<<endl;
121         else{
122             b=b/c;
123             cout<<b<<endl;
124         }
125     }
126     return 0;
127 }
View Code

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

然后那个高精度模板

虽然多

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

全部评论

相关推荐

2025-12-18 18:50
已编辑
门头沟学院 golang
牛客33637108...:重点是要事已密成,在没有进入这家公司之前,不要有任何的泄露信息,我之前跟你一样,面了一家光伏设备厂,底薪7500加上出差补贴大概有13,000左右,已经给了口头offer了,甚至要了我的在校成绩的所有信息,还向我要了三方的网签二维码,到后面还是毁约了,我干过最愚蠢的事情就是向同学透露要签三方的事,之后的失败只会让他们幸灾乐祸,这是即将结束的大学生活给我的最后一课,不要相信任何的口头三方,该面的就去面,甚至签了三方也有毁约的可能,就像我现在签了三方还在外面实习呢,春招还是要继续参加的,不能停止面试,不然到后面毁三方的时候,重新捡起的面试很麻烦的,这是我一点点小小的见解。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务