2025.1.12——1200
2025.1.12——1200
Q1. 1200
You are given a sequence
A pair of integers
;- if you simultaneously remove the elements at positions
and from the sequence , the sum of the remaining elements is at least and at most .
Your task is to determine the number of interesting pairs of integers for the given sequence
Input
- The first line contains three integers
( , ); - The second line contains
integers ( ).
Q2. 1200
Vasya has two hobbies — adding permutations
More formally, Vasya must choose exactly one permutation
Input
The first line of each test case contains a single integer
The second line of each test case contains
Q3. 1200
Jay managed to create a problem of difficulty
But Yash fears that this problem will make the contest highly unbalanced, and the coordinator will reject it. So, he decided to break it up into a problemset of
The coordinator, Aleksey, defines the balance of a problemset as the GCD of the difficulties of all sub-problems in the problemset.
Find the maximum balance that Yash can achieve if he chooses the difficulties of the sub-problems optimally.
Input
Each test case contains a single line of input containing two integers
------------------------独自思考分割线------------------------
-
观察+数论
A1.
- 优化:排序后对于每个数二分找两侧边界。
- 有点细节
A2.
- 发现性质:最后选择的数上下界差小于
。 - 排序后二分找到最多的数。
A3.
- 从答案
开始考虑,每个数必然是 的倍数, 亦为 的倍数,则 必然为 的因子,对于每个因子若能够分为至少 份,则可以作为答案。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
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
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, x, y;
cin >> n >> x >> y;
vector<int> a(n + 2);
int sum = 0;
for (int i = 1; i <= n; i++)
cin >> a[i], sum += a[i];
sort(a.begin() + 1, a.end() - 1, [](int &e1, int &e2)
{ return e1 > e2; });
int res = 0;
for (int i = 1; i <= n; i++)
{
int s = sum - a[i];
int l = 0, r = n + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (s - a[mid] >= x)
r = mid;
else
l = mid;
}
int d = r;
l = 0, r = n + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (s - a[mid] <= y)
l = mid;
else
r = mid;
}
int u = l;
// bug2(d, u);
if (d <= u)
res += u - d + 1 - (i >= d && i <= u);
}
cout << res / 2 << endl;
}
A2.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
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
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
map<int, int> has;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
has[x] = 1;
}
vector<int> a(1, 0);
for (auto [x, c] : has)
a.push_back(x);
int _n = has.size();
int res = 1;
for (int i = 1; i <= _n; i++)
{
int l = i, r = _n + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (a[mid] - a[i] < n)
l = mid;
else
r = mid;
res = max(res, l - i + 1);
}
}
// for (auto v : a)
// cout << v << ' ';
// cout << endl;
cout << res << endl;
}
A3.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
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
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int x, n;
cin >> x >> n;
int res = 1;
vector<int> t;
for (int i = 2; i <= x / i; i++)
if (x % i == 0)
{
t.push_back(i);
if (x / i - i)
t.push_back(x / i);
}
t.push_back(x);
for (auto v : t)
if (x / v >= n)
res = max(res, v);
cout << res << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!