2025.1.19——1300
2025.1.19——1300
A 1300
You are given an array
- Choose a pair of elements
and ( and ); - Choose one of the divisors of the integer
, i.e., an integer such that ; - Replace
with and with .
Determine whether it is possible to make all elements in the array the same by applying the operation a certain number of times (possibly zero).
For example, let's consider the array
- Choose
and , . Replace with , and with . The resulting array is = [ ]; - Choose
and , . Replace with , and with . The resulting array is = [ ].
After performing these operations, all elements in the array
Input
The first line of the input contains a single integer
Then follows the description of each test case.
The first line of each test case contains a single integer
The second line of each test case contains exactly
It is guaranteed that the sum of
B 1300
You have
Find the maximum number of elements in an attainable
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains a single integer
The following
------------------------思考------------------------
-
数学+思维/入手点
A
- 本质操作是移动因子/质因子。
- 从结果来看,分解质因数后发现每个质因子出现的次数都必须为
的倍数。具有充分必要性。
B
- 入手点是枚举每个数:当此数不在最后集合中时,暴力统计有多少元素没有受到影响。最后坏情况大约 6e7 , 600ms 。
- 搞了半天数据结构维护,原来暴力就行。
------------------------代码------------------------
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;
map<int, int> cnt;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
for (int j = 2; j <= x / j && x; j++)
while (x % j == 0)
{
cnt[j]++;
x /= j;
}
if (x - 1)
cnt[x]++;
}
// for (auto [x, has] : cnt)
// bug2(x, has);
bool f = 1;
for (auto [x, has] : cnt)
if (has % n)
f = 0;
cout << (f ? "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 (auto i = VEC.begin() + ST; i != VEC.end(); i++) \
cout << *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;
vector<set<int>> has(n);
set<int> t;
for (auto &s : has)
{
int cnt;
cin >> cnt;
for (int i = 0; i < cnt; i++)
{
int x;
cin >> x;
s.insert(x);
t.insert(x);
}
}
n = t.size();
int res = 0;
for (auto x : t)
{
set<int> left;
for (auto s : has)
{
auto it = s.lower_bound(x);
// bug(*it);
if (it == s.end() || *it != x)
for (auto k : s)
left.insert(k);
}
// bug2(x, left.size());
res = max(res, (int)left.size());
}
cout << res << endl;
}
// void _()
// {
// int n;
// cin >> n;
// map<int, map<int, int>> has;
// for (int i = 0; i < n; i++)
// {
// int cnt;
// cin >> cnt;
// set<int> s;
// for (int i = 0; i < cnt; i++)
// {
// int x;
// cin >> x;
// s.insert(x);
// }
// for (auto x : s)
// for (auto y : s)
// has[x][y]++;
// }
// map<int, int> w;
// for (auto [x, hs] : has)
// {
// int c = 0;
// for (auto [y, cnt] : hs)
// c += cnt == 1;
// w[x] = c;
// }
// int res = 0;
// for (auto [x, v] : w)
// res = max(res, (int)w.size() - v), bug2(x, v);
// cout << res << endl;
// }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!