zoukankan      html  css  js  c++  java
  • 1704 卡片游戏

    1704 卡片游戏

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 白银 Silver
     
     
    题目描述 Description

    桌面上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号为1~n.当至少还剩两张排时进行一下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后。输入n。输出每次扔掉的牌,以及最后剩下的牌。。

    输入描述 Input Description

    输入n

    输出描述 Output Description

    输出每次扔掉的牌,以及最后剩下的牌

    样例输入 Sample Input

    7

    样例输出 Sample Output

    1 3 5 7 4 2 6

    本来在做图论题,没想到蹦出个这个来,呵呵

    水题,一个队列就能搞定。

    #include<iostream>
    #include<queue>
    #include<cstdio>
    using namespace std;
    int n,t,num=0;
    queue<int>a;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int main()
    {
        n=read();
        for(int i=1;i<=n;i++) a.push(i);
        while(num<n-1)
        {
            printf("%d ",a.front());
            a.pop();
            t=a.front();
            a.pop();
            a.push(t);
            num++;
        }
        printf("%d
    ",a.front());
        return 0;
    }
    代码
  • 相关阅读:
    BIOS中的UEFI和Legacy启动模式
    php和java中的加密和解密
    Linux 的进程状态
    C++继承:公有,私有,保护
    编译器在构造函数里都做了些什么?
    操作符重载
    C++对象模型学习笔记
    sizeof操作符-结构体与类大小
    C++之智能指针
    C/C++笔试题整理
  • 原文地址:https://www.cnblogs.com/EvilEC/p/6045958.html
Copyright © 2011-2022 走看看