I - Intense Bit Wheel Gym - 101845I

There is a new intense giant wheel in UNAL town, in UNAL town the wheels move in counterclockwise direction, also as this wheel has n cabins, everyone and everything can play. In particular, numbers come to this attraction. However, a complete number doesn’t fit in one cabin, in fact, each cabin have space only for one bit. For this reason a number splits into its binary from and ride the wheel each bit per cabin. As numbers do not want to mess it up, the bits enter into the attraction in the same order the number is formed. Nonetheless, the wheel moves k times (entering and exiting from the attraction don’t count as moves), then when the bits have to get out of the wheel they probably don’t do it in the same order they entered, therefore making a different number.

For example, when the number 13 enter in a intense 8-bit it will look like the left side of the image below, after 5 moves the wheel will look like the right side of the image, in this case the number exiting the wheel will be 161.

You as the chief of the numbers in the UNAL town want to know how the wheel can affect the numbers that ride this attraction.

Input
First line of input contains 2 numbers n (1 ≤ n ≤ 50) and m (1 ≤ m ≤ 1000) - the quantity of cabins in the wheel and the quantity of numbers that ride in the wheel, respectively.

Next m lines of input contains each 2 integers num (0 ≤ num < 2n) and k (1 ≤ k ≤ 1018) - the number that ride the wheel and the quantity of times the wheel move, respectively.

Output
For each number that ride the wheel print the resulting number after leaving the wheel. Output this number in its decimal form.

Example
Input
8 3
1 1
13 5
17 12
Output
2
161
17
Note
Note that all numbers that ride into the wheel have exactly n bits, for example the number 13 in a 8-cabin wheel is not 1101 but 00001101 (see example).
下面是代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#define ll long long
using namespace std;
int n,m;
string s;
int main()
{
	ll i,num,j,ans;
	ll k;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        queue<char> que;
    	s.clear();
        cin>>num>>k;
        int l=0,i;
         stack<int> sta;
         while(num)
         {
           sta.push(num%2);
           num/=2;
         }
         int cnt=sta.size();
         for(i=1;i<=n-cnt;i++) sta.push(0);
         while(!sta.empty()) s+=sta.top()+'0',sta.pop();
         ll x=k%n;
         cnt=s.size();
         for(j=0;j<cnt;j++) que.push(s[j]);
         while(x--)
         {
            char hhh=que.front();
            que.pop();
            que.push(hhh);
         }
        ans=0;
        for(j=0;j<cnt;j++) s[j]=que.front(),que.pop();
        for(j=0;j<cnt;j++) ans+=(s[j]-'0')*pow(2,cnt-1-j);
        printf("%lld\n",ans);
    }
    return 0;
}

下面是wa在21的代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#define ll long long
using namespace std;
int n,m;
string s;
void binary(int x)
{
    int l=0,i;
    stack<int> sta;
    while(x)
    {
        sta.push(x%2);
        x/=2;
    }
    int cnt=sta.size();
    for(i=1;i<=n-cnt;i++) sta.push(0);
    while(!sta.empty()) s+=sta.top()+'0',sta.pop();
}
int main()
{
	ll i,num,j,ans;
	ll k;
    string s2;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        queue<char> que;
    	s.clear();
        cin>>num>>k;
        binary(num);
        ll x=k%n;
        int cnt=s.size();
        for(j=0;j<cnt;j++) que.push(s[j]);
        while(x--)
        {
            int hhh=que.front();
            que.pop();
            que.push(hhh);
        }
        ans=0;
        for(j=0;j<cnt;j++) s[j]=que.front(),que.pop();
        for(j=0;j<cnt;j++) ans+=(s[j]-'0')*pow(2,cnt-1-j);
        printf("%lld\n",ans);
    }
    return 0;
}

应该是函数调用的时候出现问题。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值