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[205][100],temp[205][100];
int jin=0,cnt=0,i,j,t,lang[200];



int main()
{
    anss[0][0]='1';
    for(i=1;i<=200;i++)
    {
        for(j=0;j<=cnt;j++)
        {
            //cout<<(anss[i-1][j]-'0'+jin)*2+'0'<<endl;
            anss[i][j]=((anss[i-1][j]-'0')*2+jin)%10+'0';
            jin=((anss[i-1][j]-'0')*2+jin)/10;
        }
        //cout<<jin<<endl;
        while(jin)
        {
            //cout<<jin<<endl;
            anss[i][++cnt]=jin%10+'0';
            jin=jin/10;
            //cout<<jin<<endl;
        }
        lang[i]=cnt;
        //cout<<anss[i]<<endl;
    }
    for(i=1;i<=200;i++)
    {
        for(j=lang[i];j>=0;j--)
        {
            temp[i][lang[i]-j]=anss[i][j];
        }
        //cout<<temp[i]<<endl;        
    }
    cin>>t;
    while(t--)
    {
        char str[200];
        cin>>str;
        //cout<<strlen(str)<<endl;
        for(i=0;i<200;i++)
        {
            int flag1=0;
            int flag2=0;
            if(strlen(str)<lang[i+1]+1)
            {
                cout<<temp[i]<<endl;
                break;
            }
            if(strlen(str)>lang[i]+1&&strlen(str)==lang[i+1]+1)
            {
                if(strcmp(temp[i+1],str)>0)
                {
                    cout<<temp[i]<<endl;
                    break;
                }
            }
            if(strlen(str)==lang[i]+1&&strlen(str)==lang[i+1]+1)
            if(strcmp(temp[i],str)<=0&&strcmp(temp[i+1],str)>0)
            {
                cout<<temp[i]<<endl;
                break;
            }
        }
    }
}

 

转载于:https://www.cnblogs.com/dyhaohaoxuexi/p/11359413.html

### 2024 ICPC Asia Regional Information #### 赛事概述 国际大学生程序设计竞赛(International Collegiate Programming Contest, ICPC)是一项全球性的编程比赛,旨在促进计算机科学教育并培养团队合作精神。每年的亚洲区域赛吸引了来自多个国家和地区的学生参与[^1]。 #### 时间安排 通常情况下,ICPC亚洲区域赛会在每年秋季举行预选赛,并于冬季举办现场决赛。具体到2024年的赛事时间表尚未公布,但可以参考往届的时间节点来推测大致的日程安排[^3]。 #### 参赛资格 参赛队伍一般由三名在校本科生组成,在指导教师的带领下完成一系列算法挑战题目。每支队伍需通过线上选拔赛获得参加线下总决赛的机会。对于有兴趣报名的同学来说,建议关注所在学校的通知以及官方渠道发布的最新消息[^4]。 #### 报名方式 各高校会组织内部选拔活动以组建代表队;成功入围者将统一注册成为正式选手。需要注意的是,不同赛区可能有不同的截止日期和特殊要求,因此务必提前做好准备并按时提交所需材料[^2]。 #### 备战指南 为了更好地迎接即将到来的比赛,可以从以下几个方面着手准备: - **学习基础知识**:深入理解数据结构、图论、动态规划等核心概念; - **练习历年真题**:熟悉各类题型及其解法模式; - **加强协作能力**:提高沟通效率,学会分工合作解决问题; - **保持良好心态**:面对高强度训练时不急不躁,调整好心理状态。 ```python def prepare_for_icpc(): study_fundamentals() practice_past_papers() enhance_teamwork_skills() maintain_positive_attitude() prepare_for_icpc() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值