河南第六届ACM省赛(Card Trick)

题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=714

题意:把n张牌倒过来数1张最上面的牌放到最下面,再把最上面的一张牌正着放到桌子上,是1,接着依次数2张最上面的牌放到最下面,再把最上面的一张牌正着放到桌子上,是2,依次类推

思路:记得教小学生的时候拿着个游戏和他们装了多少次逼,没想到省赛的题遇到了,实在是练习,要不然直接在圈里填数字就把所有情况画出来了,数据还特别蛋疼,还小于13,不知道有多少参赛选手是画圈出结果的

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>

const int inf = 0x7f7f7f7f;//2139062143
typedef long long ll;
using namespace std;

int a[15];

int main()
{
    int t;
    int i,j;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        memset(a,0,sizeof(a));
        scanf("%d",&n);
        j = 1;
        for(i=1; i<=n-1; i++)
        {
            int sum = 0;
            while(true)
            {
                if(a[j] == 0)
                {
                    sum++;
                }
                j++;
                if(j == n+1)
                {
                    j = 1;
                }
                if(sum == i)
                {
                    while(true)//找下一个没有放的位置放进去
                    {
                        if(!a[j])
                        {
                            a[j] = i;
                            break;
                        }
                        j++;
                        if(j == n+1)
                            j = 1;
                    }
                    break;
                }
            }
        }
        for(i=1; i<=n; i++)//最后一个找一个空位放进去就行了
        {
            if(a[i] == 0)
            {
                a[i] = n;
                break;
            }
        }
        printf("%d",a[1]);
        for(i=2; i<=n; i++)
        {
            printf(" %d",a[i]);
        }
        printf("\n");
    }
    return 0;
}

作者的标称,跪拜啊

 
#include<bits/stdc++.h>
using namespace std;
deque<int >vec;
int main()
{
    int ncase;
    int t,i,j;
    cin>>ncase;
    while(ncase--)
    {
        cin>>t;
        vec.push_back(t);
        for(i=t-1;i>=1;i--)
        {
            vec.push_back(i);
            for(j=1;j<=i;j++)
            {
                int temp=vec.front();
                vec.push_back(temp);
                vec.pop_front();
            }
        }
        while(!vec.empty())
        {
            printf("%d ",vec.back());
            vec.pop_back();
        }
        printf("\n");
    }
    return 0;
}

        


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值