社区讨论
求助入门赛第七题F题
题目总版参与者 8已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 9 条
- 当前快照
- 1 份
- 快照标识符
- @lrkntdsf
- 此快照首次捕获于
- 2024/01/19 21:11 2 年前
- 此快照最后确认于
- 2024/01/20 07:51 2 年前
【LGR-172-Div.4】洛谷入门赛 #19
错了几个点,有没有巨佬帮忙debug一下
CPP#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,q;
int a[10000001],b[10000001];
int cnt = 0;
void f(int x)
{
for(int i = 0; n > 0; i++)
{
a[i] = n % 2;
n= n / 2;
cnt++;
}
}
int x;
signed main()
{
int ans = 0;
cin >> n >> q;
f(n);
int tt = 1;
for(int i = cnt - 1 ;i >= 0 ;i--)
{
b[tt] = a[i];
tt++;
}
for(int i = 1;i <= q;i++)
{
int k;
cin >> k;
// for(int j = cnt - 1;j >= 0;j--)
// cout << a[j];
// puts(" ");
if(a[k - 1] == 1) continue;
int sum = 1;
for(int j = 0;j < k - 1; j++)
{
if(a[j] == 0) sum ++;
}
ans += sum;
a[0] += sum;
for(int j = 0;j < k;j++)
{
if(a[j] >= 2)
{
a[j + 1] += a[j] / 2;
a[j] = a[j] % 2;
}
}
// cnt ++;
// for(int j = cnt - 1;j >= 0;j--)
// cout << a[j];
// puts(" ");
}
cout << ans;
return 0;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...