比赛链接: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

题意:

如果 Codeforces Round #694 (Div. 2) A~D、E - 图1%2F%5Cgcd(x%2Cy)#card=math&code=lcm%28x%2Cy%29%2F%5Cgcd%28x%2Cy%29) 为一个完全平方数,那么 Codeforces Round #694 (Div. 2) A~D、E - 图2Codeforces Round #694 (Div. 2) A~D、E - 图3 相邻。给你一个数组,从 Codeforces Round #694 (Div. 2) A~D、E - 图4 秒开始,每秒钟每个元素都会被其和与其互为完全平方数的乘积替换,设Codeforces Round #694 (Div. 2) A~D、E - 图5 为数组中第 $i $ 个元素共有几个互为完全平方数的数(包含本身)。 Codeforces Round #694 (Div. 2) A~D、E - 图6 个询问,每个询问询问第 Codeforces Round #694 (Div. 2) A~D、E - 图7 秒时 Codeforces Round #694 (Div. 2) A~D、E - 图8 的最大值。

思路:

有一个明显的推理:Codeforces Round #694 (Div. 2) A~D、E - 图9 如果是完全平方数,那么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. }