• hdu 2184模拟


    /*
     * hdu2184/win.cpp
     * Created on: 2012-8-2
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    typedef unsigned long long I64u;
    typedef stack<int> ms;
    I64u powoftwo[64];
    void init() {
        powoftwo[0] = 0;
        for(int i = 1; i < 64; i++) {
            powoftwo[i] = powoftwo[i - 1] * 2 + 1;
        }
    }
    
    int fun(I64u m) {
        for(int i = 0; i < 64; i++) {
            if(m == powoftwo[i]) {
                return i;
            }
        }
        for(int i = 63; i >= 0; i--) {
            if(m > powoftwo[i]) {
                return -i;
            }
        }
        return 0;
    }
    
    void mymove(ms &sa, ms &sc, int n) {
        ms temp;
        for(int i = 0; i < n; i++) {
            temp.push(sa.top());
            sa.pop();
        }
        for(int i = 0; i < n; i++) {
            sc.push(temp.top());
            temp.pop();
        }
    }
    
    void work(ms &sa, ms &sb, ms &sc, int n, I64u m) {
        I64u ret = powoftwo[n - 1];
        if(m < ret) {
            work(sa, sc, sb, n - 1, m);
            return ;
        }
        mymove(sa, sb,  n - 1);
        m -= ret;
        if(m > 0) {
            mymove(sa, sc, 1);
            m--;
        }
        if(m > 0) {
            work(sb, sa, sc, n - 1, m);
        }
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T, n;
        init();
        scanf("%d", &T);
        I64u m;
        while(T--) {
            scanf("%d%I64u", &n, &m);
            stack<int> s[3];
            for(int i = n; i > 0; i--) {
                s[0].push(i);
            }
            work(s[0], s[1], s[2], n, m);
            for(int i = 0; i < 3; i++) {
                int size = s[i].size();
                printf("%d", size);
                ms temps;
                while(!s[i].empty()) {
                    temps.push(s[i].top());
                    s[i].pop();
                }
                for(int j = 0; j < size; j++) {
                    printf(" %d", temps.top());
                    temps.pop();
                }
                putchar('\n');
            }
        }
        return 0;
    }
  • 相关阅读:
    Python爬虫爬取网页图片
    Python爬虫爬取贴吧的帖子内容
    Android导入AS工程
    Arcgis for Silverlight学习(一)
    Silverlight学习笔记之页面跳转
    视频信号的垂直消隐和水平消隐[转]
    【DM642学习笔记八】色度重采样
    java从入门到卖肠粉系列
    [Selenium] Automation Test Manual(Selenium)
    [Selenium] Selenium私房菜(新手入门教程)
  • 原文地址:https://www.cnblogs.com/moonbay/p/2619615.html
Copyright © 2020-2023  润新知