国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

HDU2319 Card Trick

2019-11-06 08:04:36
字體:
來源:轉載
供稿:網友

Card Trick

                                                       Time Limit: 3000/1000 MS (java/Others)    Memory Limit: 65536/32768 K (Java/Others)

                                                       Total Submission(s): 327    Accepted Submission(s): 162PRoblem DescriptionThe magician shuffles a small pack of cards, holds it face down and performs the following procedure:1.The top card is moved to the bottom of the pack. The new top card is dealt face up onto the table. It is the Ace of Spades.2.Two cards are moved one at a time from the top to the bottom. The next card is dealt face up onto the table. It is the Two of Spades.3.Three cards are moved one at a time…4.This goes on until the nth and last card turns out to be the n of Spades.This impressive trick works if the magician knows how to arrange the cards beforehand (and knows how to give a false shuffle). Your program has to determine the initial order of the cards for a given number of cards, 1 ≤ n ≤ 13. InputOn the first line of the input is a single positive integer, telling the number of test cases to follow. Each case consists of one line containing the integer n. OutputFor each test case, output a line with the correct permutation of the values 1 to n, space separated. The first number showing the top card of the pack, etc… Sample Input
245 Sample Output
2 1 4 33 1 4 5 2 SourceNordic 2006用數組模擬來做,就是想的時候有點別扭。
#include<stdio.h>#include<string.h>int main(){    int n,i,l;    scanf("%d",&n);    int a[1000];    for(i=1;i<=n;i++)    {        memset(a,0,sizeof(a));        int m;        int j,k;        int cnt=2;        scanf("%d",&m);        if(m==1)            printf("1/n");        else if(m==2)            printf("2 1/n");        else        {            a[2]=1;            j=0;            k=2;            for(;;)            {               ++k;               if(a[k]==0)                   j++;               if(j==cnt+1)               {                 a[k]=cnt;                 cnt++;                 j=0;               }               if(k==m)                 k=0;               if(cnt==m+1)                break;            }            for(l=1;l<m;l++)            printf("%d ",a[l]);            printf("%d/n",a[m]);        }    }    return 0;}下面是借鑒別人用隊列做的
#include<stdio.h>#include<iostream>#include<queue>using namespace std;queue<int>q;int flag;void output(){    int temp=q.front();    q.pop();    while(!q.empty())        output();    if(flag==0)    {        printf("%d",temp);        flag=1;    }    else    printf(" %d",temp);}int main(){    int n;    scanf("%d",&n);    while(n--)    {        int t;        scanf("%d",&t);        while(t>0)        {            q.push(t);            int cnt=t;            t--;            while(cnt--)            {                int temp=q.front();                q.pop();                q.push(temp);            }        }        flag=0;        output();        printf("/n");    }    return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东乡县| 东乌珠穆沁旗| 榕江县| 都昌县| 获嘉县| 安庆市| 北京市| 上犹县| 宜宾县| 屏东市| 永和县| 明星| 会理县| 巨鹿县| 温州市| 浪卡子县| 金湖县| 芜湖市| 华容县| 大连市| 山东省| 江油市| 临桂县| 原阳县| 铜陵市| 溧水县| 繁峙县| 江阴市| 西乌| 宁乡县| 南阳市| 天柱县| 福海县| 金沙县| 济源市| 固镇县| 烟台市| 鹤岗市| 滨海县| 教育| 阜新|