Codeforces Round #694 (Div. 2) A~D、E
比赛链接:Here
1471A. Strange Partition
题意:
给一个数组,数组中的所有元素可以任意合并,求数组的每个元素除以x上取整的和,求结果的最大值和最小值。
思路:
瞎猜。最小值肯定是都合并在一起,最大值是分开。
【AC Code】
const int N = 1e5 + 10;
ll a[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _; for (cin >> _; _--;) {
ll n, x;
cin >> n >> x;
ll s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s1 += a[i];
s2 += (a[i] + x - 1) / x;
}
cout << (s1 + x - 1) / x << " " << s2 << "\n";
}
}
1471B. Strange List
题意:
给你一数组,一个x,从前往后遍历数组(也会遍历后面加进来的元素),如果当前元素a可以被x除尽,则在数组末尾加上x个a/x。如果不能被除尽则停止,问数组的元素之和。
思路:
可以很显然看出一个性质如果a/x也能被x除尽,那么结果增加a,因为一共有x个a/x。 模拟,如果能除尽,则结果加上当前元素,不能除尽则跳出。
【AC Code】
const int N = 1e5 + 10;
ll a[N], b[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _; for (cin >> _; _--;) {
ll n, x;
cin >> n >> x;
ll s = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i], b[i] = a[i];
s += a[i];
}
for (int i = 0; i < n; i = (i + 1) % n) {
if (b[i] % x == 0) s += a[i], b[i] = b[i] / x;
else break;
}
cout << s << "\n";
}
}
1471C. Strange Birthday Party
题意:
商品按价钱从小到大排序,每个商品只能拿1次。 n个客人,每个客人有一个权值,只能拿下标比权值小的商品或者给客人下标为权值的商品对应的现金。
思路:
排序贪心,权值大的先拿前面的,序号小的后拿,如果不存在了,就拿现金。
【AC Code】
const int N = 3e5 + 10;
ll k[N], c[N], st[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _; for (cin >> _; _--;) {
ll n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> k[i];
for (int i = 1; i <= m; ++i) st[i] = 0;
for (int i = 1; i <= m; ++i) cin >> c[i];
sort(k + 1, k + 1 + n);
ll ans = 0;
int j = 1;
for (int i = n; i >= 1; i -= 1) {
if (c[k[i]] > c[j] && !st[j] && j <= m) {
ans += c[j];
st[j] = 1;
j++;
} else ans += c[k[i]];
}
cout << ans << "\n";
}
}
1471D. Strange Definition
题意:
如果
思路:
有一个明显的推理:
【AC Code】
ll primes[1001000];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
primes[1] = 1;
for (int i = 2; i <= 1000100; i++) {
if (!primes[i]) {
primes[i] = i;
for (int j = i * 2; j <= 1000100; j += i)
if (!primes[j]) primes[j] = i;
}
}
int _; for (cin >> _; _--;) {
unordered_map<ll, ll> hash;
int n;
cin >> n;
hash[1] = 0;
for (int i = 1; i <= n; i++) {
int h = 1, x;
cin >> x;
while (primes[x] != 1) {
int t = 0;
int j = primes[x];
while (x % j == 0) {
x /= j;
t++;
}
if (t % 2) h *= j;
}
hash[h]++;
}
ll cnt1 = 0, cnt2 = 0;
for (auto i : hash) cnt1 = max(cnt1, i.second);
for (auto &i : hash)
if (i.first != 1 && i.second % 2 == 0) {
hash[1] += i.second;
i.second = 0;
}
for (auto i : hash) cnt2 = max(cnt2, i.second);
int q;
cin >> q;
while (q--) {
ll x;
cin >> x;
if (x == 0) cout << cnt1 << endl;
else cout << cnt2 << endl;
}
}
}
1471F. Strange Housing
没写出来...
题意:
给你节点和边,染色,染色的住老师,未染色的住学生。 要求:相邻的节点不能同时染色,只有染色的节点和不染色的节点相邻的边才成立,要求图联通。
思路:
暴力贪心即可。如果与当前节点相邻的所有节点没老师,那当前节点就放老师,否则不放。 如果有节点未遍历到,则输出NO。 证明:老师一定不相邻,一定联通,放学生时周围一定有老师。
【AC Code】
#define int long long
const int maxn = 300010;
vector<int> g[maxn];
int cnt;
int st[maxn];
void dfs(int u) {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < g[u].size(); i++)
if (st[g[u][i]]) {
if (st[g[u][i]] == 1) sum1++;
else sum2++;
// cout << st[g[u][i]] << endl;
// cout << "---" << endl;
}
// cout << sum1 << endl;
if (sum1 == 0) st[u] = 1;
else st[u] = 2;
for (int i = 0; i < g[u].size(); i++)
if (!st[g[u][i]]) dfs(g[u][i]);
}
void work() {
cnt = 0;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) st[i] = 0, g[i].clear();
while (m--) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1);
int cnt = 0, flag = 0;
for (int i = 1; i <= n; i++) {
if (st[i] == 1) cnt++;
if (!st[i]) flag = 1;
}
if (flag) cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << cnt << endl;
for (int i = 1; i <= n; i++)
if (st[i] == 1) cout << i << " ";
cout << endl;
}
}
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 分享4款.NET开源、免费、实用的商城系统
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 5. Nginx 负载均衡配置案例(附有详细截图说明++)
2020-09-02 博弈论经典模型解析(入门级)
2020-09-02 Problem 1342B - Binary Period (思维)
2020-09-02 SCOI2005 互不侵犯 (状态压缩入门题)
2020-09-02 位运算的奇技淫巧(二)