比赛链接:Here

1471A. Strange Partition

题意:

给一个数组,数组中的所有元素可以任意合并,求数组的每个元素除以x上取整的和,求结果的最大值和最小值。

思路:

瞎猜。最小值肯定是都合并在一起,最大值是分开。

【AC Code】

  1. const int N = 1e5 + 10;
  2. ll a[N];
  3. int main() {
  4. ios::sync_with_stdio(false), cin.tie(nullptr);
  5. int _; for (cin >> _; _--;) {
  6. ll n, x;
  7. cin >> n >> x;
  8. ll s1 = 0, s2 = 0;
  9. for (int i = 1; i <= n; i++) {
  10. cin >> a[i];
  11. s1 += a[i];
  12. s2 += (a[i] + x - 1) / x;
  13. }
  14. cout << (s1 + x - 1) / x << " " << s2 << "\n";
  15. }
  16. }

1471B. Strange List

题意:

给你一数组,一个x,从前往后遍历数组(也会遍历后面加进来的元素),如果当前元素a可以被x除尽,则在数组末尾加上x个a/x。如果不能被除尽则停止,问数组的元素之和。

思路:

可以很显然看出一个性质如果a/x也能被x除尽,那么结果增加a,因为一共有x个a/x。 模拟,如果能除尽,则结果加上当前元素,不能除尽则跳出。

【AC Code】

  1. const int N = 1e5 + 10;
  2. ll a[N], b[N];
  3. int main() {
  4. ios::sync_with_stdio(false), cin.tie(nullptr);
  5. int _; for (cin >> _; _--;) {
  6. ll n, x;
  7. cin >> n >> x;
  8. ll s = 0;
  9. for (int i = 0; i < n; ++i) {
  10. cin >> a[i], b[i] = a[i];
  11. s += a[i];
  12. }
  13. for (int i = 0; i < n; i = (i + 1) % n) {
  14. if (b[i] % x == 0) s += a[i], b[i] = b[i] / x;
  15. else break;
  16. }
  17. cout << s << "\n";
  18. }
  19. }

1471C. Strange Birthday Party

题意:

商品按价钱从小到大排序,每个商品只能拿1次。 n个客人,每个客人有一个权值,只能拿下标比权值小的商品或者给客人下标为权值的商品对应的现金。

思路:

排序贪心,权值大的先拿前面的,序号小的后拿,如果不存在了,就拿现金。

【AC Code】

  1. const int N = 3e5 + 10;
  2. ll k[N], c[N], st[N];
  3. int main() {
  4. ios::sync_with_stdio(false), cin.tie(nullptr);
  5. int _; for (cin >> _; _--;) {
  6. ll n, m;
  7. cin >> n >> m;
  8. for (int i = 1; i <= n; ++i) cin >> k[i];
  9. for (int i = 1; i <= m; ++i) st[i] = 0;
  10. for (int i = 1; i <= m; ++i) cin >> c[i];
  11. sort(k + 1, k + 1 + n);
  12. ll ans = 0;
  13. int j = 1;
  14. for (int i = n; i >= 1; i -= 1) {
  15. if (c[k[i]] > c[j] && !st[j] && j <= m) {
  16. ans += c[j];
  17. st[j] = 1;
  18. j++;
  19. } else ans += c[k[i]];
  20. }
  21. cout << ans << "\n";
  22. }
  23. }

1471D. Strange Definition

题意:

如果 \(lcm(x,y)/\gcd(x,y)\) 为一个完全平方数,那么 \(x\) 和 \(y\) 相邻。给你一个数组,从 \(0\) 秒开始,每秒钟每个元素都会被其和与其互为完全平方数的乘积替换,设\(d_i\) 为数组中第 $i $ 个元素共有几个互为完全平方数的数(包含本身)。 \(q\) 个询问,每个询问询问第 \(i\) 秒时 \(d\) 的最大值。

思路:

有一个明显的推理:\(x*y\) 如果是完全平方数,那么x和y相邻。 那么我们把所有元素的偶数质因子都筛掉,设为core数组,那么如果core[x]=core[y],那么x和y相邻。 当询问为0,我们只需要输出出现次数最多的core。 当询问不为0,比如为1,那么core出现为偶数次的下次都会为1,如果出现奇数次下次不变,特例当core为1时无论奇偶都不变。所以重新统计。 当询问大于1,我们可以推一下,结果与1相同。

【AC Code】

  1. ll primes[1001000];
  2. int main() {
  3. ios::sync_with_stdio(false), cin.tie(nullptr);
  4. primes[1] = 1;
  5. for (int i = 2; i <= 1000100; i++) {
  6. if (!primes[i]) {
  7. primes[i] = i;
  8. for (int j = i * 2; j <= 1000100; j += i)
  9. if (!primes[j]) primes[j] = i;
  10. }
  11. }
  12. int _; for (cin >> _; _--;) {
  13. unordered_map<ll, ll> hash;
  14. int n;
  15. cin >> n;
  16. hash[1] = 0;
  17. for (int i = 1; i <= n; i++) {
  18. int h = 1, x;
  19. cin >> x;
  20. while (primes[x] != 1) {
  21. int t = 0;
  22. int j = primes[x];
  23. while (x % j == 0) {
  24. x /= j;
  25. t++;
  26. }
  27. if (t % 2) h *= j;
  28. }
  29. hash[h]++;
  30. }
  31. ll cnt1 = 0, cnt2 = 0;
  32. for (auto i : hash) cnt1 = max(cnt1, i.second);
  33. for (auto &i : hash)
  34. if (i.first != 1 && i.second % 2 == 0) {
  35. hash[1] += i.second;
  36. i.second = 0;
  37. }
  38. for (auto i : hash) cnt2 = max(cnt2, i.second);
  39. int q;
  40. cin >> q;
  41. while (q--) {
  42. ll x;
  43. cin >> x;
  44. if (x == 0) cout << cnt1 << endl;
  45. else cout << cnt2 << endl;
  46. }
  47. }
  48. }

1471F. Strange Housing

没写出来...

题意:

给你节点和边,染色,染色的住老师,未染色的住学生。 要求:相邻的节点不能同时染色,只有染色的节点和不染色的节点相邻的边才成立,要求图联通。

思路:

暴力贪心即可。如果与当前节点相邻的所有节点没老师,那当前节点就放老师,否则不放。 如果有节点未遍历到,则输出NO。 证明:老师一定不相邻,一定联通,放学生时周围一定有老师。

【AC Code】

  1. #define int long long
  2. const int maxn = 300010;
  3. vector<int> g[maxn];
  4. int cnt;
  5. int st[maxn];
  6. void dfs(int u) {
  7. int sum1 = 0, sum2 = 0;
  8. for (int i = 0; i < g[u].size(); i++)
  9. if (st[g[u][i]]) {
  10. if (st[g[u][i]] == 1) sum1++;
  11. else sum2++;
  12. // cout << st[g[u][i]] << endl;
  13. // cout << "---" << endl;
  14. }
  15. // cout << sum1 << endl;
  16. if (sum1 == 0) st[u] = 1;
  17. else st[u] = 2;
  18. for (int i = 0; i < g[u].size(); i++)
  19. if (!st[g[u][i]]) dfs(g[u][i]);
  20. }
  21. void work() {
  22. cnt = 0;
  23. int n, m;
  24. cin >> n >> m;
  25. for (int i = 1; i <= n; i++) st[i] = 0, g[i].clear();
  26. while (m--) {
  27. int a, b;
  28. cin >> a >> b;
  29. g[a].push_back(b);
  30. g[b].push_back(a);
  31. }
  32. dfs(1);
  33. int cnt = 0, flag = 0;
  34. for (int i = 1; i <= n; i++) {
  35. if (st[i] == 1) cnt++;
  36. if (!st[i]) flag = 1;
  37. }
  38. if (flag) cout << "NO" << endl;
  39. else {
  40. cout << "YES" << endl;
  41. cout << cnt << endl;
  42. for (int i = 1; i <= n; i++)
  43. if (st[i] == 1) cout << i << " ";
  44. cout << endl;
  45. }
  46. }

Codeforces Round #694 (Div. 2) A~D、E的更多相关文章

  1. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  2. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  3. Codeforces Round #434 (Div. 2)【A、B、C、D】

    Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...

  4. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  5. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  6. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  7. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  8. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  9. Codeforces Round #430 (Div. 2) 【A、B、C、D题】

    [感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...

  10. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

随机推荐

  1. PEP9

    利用循环语句 counter 是计数器 需要在后面输入个3才是3个数字之和 Set sum to 0 Set counter to 0 Set limit to number of values to ...

  2. excel柱状图自定x轴y轴

    在Excel中,柱状图是一种常用的数据可视化方式,可以直观地展示不同数据之间的比较关系.默认情况下,Excel会根据数据自动生成X轴和Y轴的刻度和标签.然而,如果你想要自定义X轴和Y轴,在柱状图中显示 ...

  3. k8s~envoy上添加wasm插件

    先查看这篇文章k8s~envoy的部署 当在Kubernetes中使用Envoy的WASM过滤器时,WASM过滤器会与Envoy一起部署在同一个Pod中,并与后端服务进行通信.以下是一个简单的关系图示 ...

  4. Django笔记四十四之Nginx+uWSGI部署Django以及Nginx负载均衡操作

    本文首发于公众号:Hunter后端 原文链接:Django笔记四十四之Nginx+uWSGI部署Django以及Nginx负载均衡操作 这一篇笔记介绍如何使用 Nginx + uWSGI 来部署 Dj ...

  5. Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same(解决)

    问题描述 在使用pytorch训练经典的MNIST数据集时,运行时,出现了以下的问题: Input type (torch.FloatTensor) and weight type (torch.cu ...

  6. 开源.NetCore通用工具库Xmtool使用连载 - 图像处理篇

    [Github源码] <上一篇> 介绍了Xmtool工具库中的扩展动态对象,今天我们继续为大家介绍其中的图像处理类库. 在我们的软件系统中,经常需要对图片进行各种各样的处理:例如最常见的头 ...

  7. Windows上安装jenkins

    官网下载jenkins https://www.jenkins.io/zh/download/ 选择Windows版本下载,安装 注意,需要java11,17或21才能安装 java下载地址  htt ...

  8. Centos 利用本地镜像安装yum源

    前提 在"设置"中确保两点 1.勾选"已连接" 2.添加上本地的"centos.iso"镜像文件 切换到用户目录 cd / 新建一个iso目 ...

  9. maven系列:聚合与继承

    目录 一.聚合 创建Maven模块,设置打包类型为pom 设置当前聚合工程所包含的子模块名称 二. 继承 问题导入 创建Maven模块,设置打包类型为pom 在父工程的pom文件中配置依赖关系(子工程 ...

  10. Windows下编译64位CGAL

    目录 1. 准备 2. CMake构建 1. 准备 CGAL的官网准备了压缩包和安装程序两种类型的的源代码,推荐使用安装程序包,因为其中自带了编译好的gmp和mpfr库.gmp和mpfr是CGAL的依 ...