zoukankan      html  css  js  c++  java
  • 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;
                }
            }
        }
    }
  • 相关阅读:
    页面跳转刷新
    表格表头绘制对角线(不固定表格宽高)
    发送邮件的工具类
    重写equals()和hashCode()
    设计模式--原型模式[转载]
    设计模式--外观模式
    设计模式--代理模式
    js处理json js递归
    MySQL锁详解
    开发一个微信小程序实例教程
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/11359413.html
Copyright © 2011-2022 走看看