2025.1.22——1300
2025.1.22——1300
A 1300
Your friends have an array of
A permutation of
The array of prefix sums of the array
For example, the original permutation was
It can also be shown that the array
Input
The first line contains a positive number
The first line of the description of each test case contains a positive number
The second line of the description of each test case contains
It is guaranteed that the sum of
B 1300
You are given an integer
To do that, you can do the following operation:
- select a divisor
of , then change to , i.e. reduce by . (We say that is a divisor of if is an positive integer and there exists an integer such that .)
There is an additional constraint: you cannot select the same value of
For example, for
Output any scheme which reduces
Input
Each test contains multiple test cases. The first line contains the number of test cases
The only line of each test case contains a single integer
------------------------思考------------------------
-
差分前缀/结论+二进制/因子/lowbit/数学
A
- 差分一下,分析下两种情况即可。
B
- 发现策略:
是 的一个因子。
------------------------代码------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
int las = 0;
map<int, int> cnt;
for (int i = 1; i < n; i++)
{
int x;
cin >> x;
cnt[x - las]++;
las = x;
}
int ned = 0;
int f = 0;
for (auto [v, ct] : cnt)
if (ct > 1 || v > n)
f = v;
int nohas = 0;
for (int i = 1; i <= n; i++)
if (!cnt[i])
nohas++, ned += i;
cout << ((nohas == 1 || (nohas == 2 && f == ned)) ? "YES" : "NO");
el;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
auto lowbit = [](int x)
{
return x & -x;
};
vector<int> res{n};
for (;;)
{
int bit = lowbit(n);
if (bit == n)
break;
n -= bit;
res.push_back(n);
}
while (n > 1)
{
int bit = lowbit(n) >> 1;
n -= bit;
res.push_back(n);
}
cout << res.size();
el;
bugv(res, 0);
}
// void _()
// {
// int x;
// cin >> x;
// auto get = [](int n)
// {
// vector<int> t{1};
// for (int i = 2; i <= n / i; i++)
// if (n % i == 0)
// {
// t.push_back(i);
// if (i - n % i)
// t.push_back(n % i);
// }
// return t;
// };
// map<int, int> cnt;
// set<int> res{x, 1};
// bool has = 0;
// function<void(int)> dfs = [&](int n)
// {
// if (n == 1)
// {
// if (!has)
// {
// has = 1;
// cout << res.size();
// el;
// for (auto it = res.rbegin(); it != res.rend(); it++)
// cout << *it << ' ';
// el;
// }
// return;
// }
// // bug(n);
// // for (auto it = res.rbegin(); it != res.rend(); it++)
// // cout << *it << ' ';
// // el;
// auto t = get(n);
// sort(t.rbegin(), t.rend());
// // bug(t.size());
// for (auto v : t)
// if (cnt[v] < 2 && n - v > 0)
// {
// cnt[v]++;
// res.insert(n - v);
// dfs(n - v);
// cnt[v]--;
// res.erase(n - v);
// }
// };
// dfs(x);
// }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!