UVA 10940 Throwing cards away II

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   for   div   sp   

題意略;

先暴力打表發現規律

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.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}#define MAXN 500003vector<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\n",tab[i][tmp-1]);    }    return 0;}

 

UVA 10940 Throwing cards away II

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.