小沙の金银阁

题目

思路

从后往前推,每次取当前灵石数的一半即可。

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>

using namespace std;
#define _CRT_SECURE_NO_WARNINGS 1
#define ll long long
#define pub push_back
#define pob pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 2e9
#define llf 1e19
#define endl "\n"
const ll mod = 1e9 + 7;

ll qpow(ll base, ll power)
{
	ll res = 1;
	while (power > 0)
	{
		if (power & 1) res = base * res % mod;
		power >>= 1;
		base = base * base % mod;
	}
	return res;
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

double dis(double x, double y, double x1, double y1)
{
	return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
double dis1(double x, double y, double z, double x1, double y1, double z1)
{
	return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1));
}
double chaji(double x1, double x2, double y1, double y2)
{
	return x1 * y2 - x2 * y1;
}

ll n, m;
ll ans[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	ll i, nn;
	cin >> n >> m;
	nn = n;
	while (nn > 1)
	{
		if (m % 2 == 0) ans[nn] = m / 2;
		else ans[nn] = m / 2 + 1;
		m = m / 2;
		nn--;
		if (m < 1)
		{
			cout << -1;
			return 0;
		}
	}
	ans[1] = m;
	for (i = 1; i <= n; i++) cout << ans[i] << ' ';
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值