Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Intuitive coding problem. But several details to take care.

#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;

bool play(unsigned long long v)
{
    std::bitset<64> b(v);

    int lastOnBit = 63;
    bool bRet = true;
    while (v != 1)
    {
        if (b.count() == 1)
        {
            v >>= 1;
        }
        else
        {
            int i;
            for (i = lastOnBit; i >= 0; i--)
            {
                if (b[i]) break;
            }
            lastOnBit = i;
            v <<= (64 - i);
            v >>= (64 - i);
        }
        b = v;
        bRet = !bRet;
    }

    return bRet;
}

int main() 
{
    int t; cin >> t;
    while (t--)
    {
        unsigned long long v; cin >> v;
        cout << (play(v) ? "Richard" : "Louise") << endl;
    }
    return 0;
}
posted on 2015-04-20 07:34  Tonix  阅读(205)  评论(0编辑  收藏  举报