求帮帮D为只过了50%,看和大佬思路也差不多

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>

using namespace std;
const int mod = 998244353;
#define ll long long

ll quick_mi(ll a, ll b)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)
			ans = ans * a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

int n, m;

ll ju(ll x, ll tm)
{
	ll ans = 0;
	int w = 0;
	while (x != 0)
	{
		if ((tm >> 1) < x)
		{
			x -= (tm >> 1) + 1;
			ans = (1 << w) + ans;
		}
		else
		{
			ans = (0 << w) + ans;
		}
		tm = tm >> 1;
		w++;
	}
	return ans;
}

void solve()
{
	cin >> n >> m;
	ll tmp = quick_mi(2, n) - 1;
	ll x;
	while (m--)
	{
		cin >> x;
		cout << ju(x, tmp) << endl;
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
//	cin >> T;
	while (T--)
		solve();

	return 0;
}

}

全部评论
            35  ans = (1ll << w) + ans;
点赞
送花
回复 分享
发布于 05-10 21:10 四川
此题已解,只需改该35行 1 << w为1ll << w即可
点赞
送花
回复 分享
发布于 05-10 21:13 湖南
国泰君安
校招火热招聘中
官网直投

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务