zoukankan      html  css  js  c++  java
  • Gym–101061A Cards(有待更新)

    time limit per test

    2.0 s

    memory limit per test

    64 MB

    input

    standard input

    output

    standard output

    Omar has a deck of cards. Every card has a unique integer number written on it. He says that his cards are numbered starting from 1, and if a card with number N exists, then a card with number N + 1 exists. Yes he may have an infinite sequence !

    Yesterday when he went to school, his little brother Samir played with his cards by sorting them into two boxes according to the numbers written on them by repeating the following two steps:

    1. Take the card with the smallest number, let it be X.
    2. Put the card with number X in the first box and put the card with number 2 * X in the second box.
    So the first few numbers in the boxes will be:

    First box : 1, 3, 4, 5, 7, ...

    Second box : 2, 6, 8, 10, 14, ...

    Omar came back home and he asked Samir for the card with number Q written on it. Help Samir to find out in which box he can find the required card.

    Input

    Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases .

    T lines follow, each describing a test case consisting of a single integer Q (1 ≤ Q ≤ 1018)

    Output

    For every test case print "First Box" if the card is in the first box or "Second Box" otherwise.

    Example

    input

    Copy

    3
    1
    6
    1024

    output

    Copy

    First Box
    Second Box
    First Box
    我该怎么说呢?其实这题我想了好久,人家都是五分钟以内就ac的,我花了一个小时。。。
    我开始在想用STL中的set容器存放1~n个元素,然后让set迭代器从1遍历到n,不断删除i的两倍对应的数字,同时set迭代器移动到下一个没被删除的元素上继续上述操作,然后在set容器中
    查找是否有n这个元素,我觉得这样做思路是对的,但我不知道怎样去实现。。。
    没办法只好换一种思路:发现只要考虑偶数,而且偶数中只有4、12、16、20、28、36、44、48……这些在First Box中,于是就在这里面找规律。。。
    最后终于AC了;
    AC代码:
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    typedef long long ll;
    using namespace std;
    int main(){
        int t;
        ll n;
        cin>>t;
        while(t--){
            scanf("%lld",&n);
            if(n%2!=0) printf("First Box
    ");    
            else{
                int count=0;
                ll c=n;
               while(c%2==0){
                   c/=2;
                   count++;
               }
               if(count%2==0) printf("First Box
    ");
               else printf("Second Box
    ");    
            }
        }
        return 0;
    }
    天晴了,起飞吧
  • 相关阅读:
    minicap编译示例
    uniapp H5项目中使用腾讯地图sdk
    腾讯地图打车乘客端小车平滑移动-安卓篇
    地图定位打卡功能示例
    腾讯位置服务个性化图层创建及发布
    腾讯位置服务GPS轨迹回放
    使用腾讯地图实现汽车沿轨迹行驶功能
    地图GPS轨迹录制
    腾讯地图实现微信小程序地图定位教程
    基于腾讯地图定位组件实现周边POI远近排序分布图
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/11380222.html
Copyright © 2011-2022 走看看