zoukankan      html  css  js  c++  java
  • Magic Master (The 2019 Asia Nanchang First Round Online Programming Contest)

    John is not only a magic master but also a shuffling master.  

    Famous though he is, he likes interacting with his fans by playing a game with his fantastic shuffling skills. 

    The game shows as follows: 

    He first shows a deck of pokers contains NN cards indexed 1,2,dots ,N1,2,,N and all the cards are the same. He notes that the side contains numbers as the front side and the other side as the back. Later he selects one of his fans to choose a positive integer MM that is not greater than 1010. After that, he will shuffle the cards purposefully and put it on the desktop. Note that at this moment the front sides of the cards are facing to the desk. 

    Then, the selected fans should perform the following steps until there is no card on the desk. 

    1. Place the card on the top of the piles to John's hand. If there are already some cards in his hand, put it on the top of them. 
    2. If there remain cards on the desk:

    (a) Put a card from the top of the piles to the bottom of it.

    (b) Execute the step (aa) of MM times.

    (c) Go to step 11.

    Next, it is time to witness the miracle.  

    John will continually overturn the cards on his hand top to bottom, and we will find that the cards are always in decreasing order. 

    One day, one of John's fans, Tom, a smart JBer, understands the key to this magic. He turns to you and comments that the key to that magic is the shuffling John did previously. For any number MM, he will turn the cards in a specific order after the shuffling. As you are not as smart as Tom, you should find the index of the KKth cards from the top of the piles after the shuffling.

    Input

    The first line contain a positive integer T (1le T le10)T(1T10) – the number of test cases.

    For each test cases, the first line contain a positive integer N (1 le N le 40000000)N(1N40000000) , indicating the numberof cards.

    The second line contain a positive integer M (1le M le 10)M(1M10) – the number the fans select.

    The third line contain an integer Q (1 le Q le 100)Q(1Q100) – indicating that there are QQ questions.

    Next, there are QQ lines, each with an integer K (1 le K le N)K(1KN) – representing a query.

    Output

    For each query, you should output the index of the KKth cards from the top of the piles after the shuffling.

    样例输入

    1
    5
    1
    2
    2
    3
    

    样例输出

    5
    2

    样例解释

    Sample description - The indexs of the cards after the shuffling are: 1~5~2~4~31 5 2 4 3 (Left is top)

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<stack>
    using namespace std;
    typedef long long ll;
    int ans[40000000];
    queue<int>q;int x;
    int main()
    {
        ll n,m;
        ll t;scanf("%lld",&t);
        while(t--)
        {scanf("%lld%lld",&n,&m);
            while(!q.empty())
                q.pop();
            for(int i=n;i>1;i--)
            {
                q.push(i);
                for(int j=1;j<=m;j++)
                {
                     ll k=q.front();
                q.pop();
                q.push(k);
                }
            }
            ans[1]=1;
            for(int i=n;i>1;i--)
            {
                ans[i]=q.front();
                //cout<<ans[i]<<' ';
                q.pop();
            }
            int ff;scanf("%d",&ff);
            for(int i=1;i<=ff;i++)
            {
    
                scanf("%d",&x);
                printf("%d
    ",ans[x]);
            }
        }
    }
    所遇皆星河
  • 相关阅读:
    C#中利用iTextSharp开发二维码防伪标签(1)
    delphi 数据库中Connection与Query连接数量问题思考
    cPanel 安装方法
    招商行用卡人工服务方式
    软链接的创建和查看
    zencart低版本由php5.2.17升级PHP5.3环境下错误及解决方案
    EXCEL应用:高级筛选里的条件或和与的条件怎么写 例:不包含,包含等
    array_walk与array_map 的不同 array_filter
    zen cart global $db 这噶哒
    hdu 5655 CA Loves Stick
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11488851.html
Copyright © 2011-2022 走看看