P16224 [蓝桥杯 2026 省 A] A. 均衡数 · znzryb
## 题目大意
# P16224 [蓝桥杯 2026 省 A] 均衡数
## 题目描述
如果一个正整数的二进制表示中(无前导 $0$),$1$ 的数量和 $0$ 的数量相同,则我们称其为一个“均衡数”。
现在,请你找到一个均衡数 $x$,使得 $|2026202620262026 - x|$ 的值最小。若存在多个均衡数使得 $|2026202620262026 - x|$ 的值相同且最小,则取其中最小的一个。
## 输入格式
无
## 输出格式
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
## 输入输出样例 #1
### 输入 #1
```
```
### 输出 #1
```
```
## 思路讲解
说白了,最靠近的就是 **50 位最大均衡数**和 **52 位最小均衡数**。
这个是 52 位最小均衡数,比这个 50 位的最大的更接近,故选这个。
```cpp
>>> bin(2251799847239679)
'0b1000000000000000000000000001111111111111111111111111'
>>>
```
## AC代码
AC
[https://www.luogu.com.cn/record/273571661](https://www.luogu.com.cn/record/273571661)
::: 源代码
```cpp
// teamname: Gospel_rock
/**
* Problem: P16224 [蓝桥杯 2026 省 A] 均衡数
* Contest:
* Judge: Luogu
* URL: https://www.luogu.com.cn/problem/P16224?contestId=320702
* Created: 2026-04-12 01:08:52
* Author: Gospel_rock
* My blog: https://znzryb.com/
*
* Powered by AutoCp https://github.com/Pushpavel/AutoCp
*/
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define lson(o) (o<<1)
#define rson(o) (o<<1|1)
#define SZ(a) ((long long) a.size())
#define debug(var) cerr << #var <<" = ["<<var<<"]"<<"\n";
#define debug1d(a) \
cerr << #a << " = ["; \
for (int i = 0; i < (int)(a).size(); i++) \
cerr << (i ? ", " : "") << a[i]; \
cerr << "]\n";
#define debug2d(a) \
cerr << #a << " = [\n"; \
for (int i = 0; i < (int)(a).size(); i++) \
{ \
cerr << " ["; \
for (int j = 0; j < (int)(a[i]).size(); j++) \
cerr << (j ? ", " : "") << a[i][j]; \
cerr << "]\n"; \
} \
cerr << "]\n";
#define cend cerr<<"\n-----------\n"
#define fsp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using DB = double;
using i128 = __int128;
using CD = complex<double>;
static constexpr ll MAXN = (ll)1e6+10, INF = (1ll<<61)-1;
static constexpr ll mod = 998244353; // (ll)1e9+7;
static constexpr double eps = 1e-8;
const double PI = acos(-1.0);
ll lT,testcase;
/*
*
*/
struct Solve {
// ll N;
Solve() {
// cin >> N;
// cout<<"2251799847239679";
ll ans=(1ll<<51)+(1ll<<25)-1;
cout<<ans<<"\n";
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef LOCAL
cout.setf(ios::unitbuf); // 无缓冲流,方便我们调试
#endif
// cin >> lT;
// for (testcase=1;testcase<=lT;++testcase)
Solve solve;
return 0;
}
/*
9003 0271 3419 402
*/
```
:::
## 心路历程(WA,TLE,MLE……)