• UVA 10940 Throwing cards away II


    题意略;

    先暴力打表发现规律

    N=1 ans=1
    N=2 ans=2
    N=3 ans=2
    N=4 ans=4
    N=5 ans=2
    N=6 ans=4
    N=7 ans=6
    N=8 ans=8
    N=9 ans=2
    N=10 ans=4
    N=11 ans=6
    N=12 ans=8
    N=13 ans=10
    N=14 ans=12
    N=15 ans=14
    N=16 ans=16
    N=17 ans=2
    N=18 ans=4
    N=19 ans=6
    N=20 ans=8
    N=21 ans=10
    N=22 ans=12
    N=23 ans=14
    N=24 ans=16
    N=25 ans=18
    N=26 ans=20
    N=27 ans=22
    N=28 ans=24
    N=29 ans=26
    N=30 ans=28
    N=31 ans=30
    N=32 ans=32

    这规律很明显了就略了。。直接上代码了

    #include <map>
    #include <set>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define PI 3.1415926535897932626
    using namespace std;
    int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
    #define MAXN 500003
    vector<int>tab[20];
    int num[20];
    int N;
    void init()
    {
        for (int i=0;i<20;i++) tab[i].clear();
        tab[0].push_back(1);
        for (int i=1;i<20;i++)
        {
            int limit=1<<i;
            int cas=2;
            while (cas<=limit)
            {
                tab[i].push_back(cas);
                cas+=2;
            }
        }
        num[0]=1;
        for (int i=1;i<20;i++) num[i]=num[i-1]+tab[i].size();
    }
    int main()
    {
        init();
        while (scanf("%d",&N)!=EOF)
        {
            if (N==0) break;
            if (N==1) {puts("1");continue;}
            int cas=0,i;
            for ( i=0;i<20;i++)
            {
                cas+=tab[i].size();
                if (cas>=N) break;
            }
            int tmp=N-num[i-1];
            printf("%d
    ",tab[i][tmp-1]);
        }
        return 0;
    }
  • 相关阅读:
    nyoj112-指数运算
    nyoj51-管闲事的小明
    nyoj29-求置转换问题
    nyoj24-素数 距离问题
    nyoj22-素数求和问题
    nyoj23-取石子(一)
    nyoj4-ASCII码排序
    nyoj169-素数
    并查集:CDOJ1593-老司机破阵 (假的并查集拆除)
    线段树: CDOJ1598-加帕里公园的friends(区间合并,单点更新)
  • 原文地址:https://www.cnblogs.com/Commence/p/3980249.html
Copyright © 2020-2023  润新知