Codeforces Round #505 (Div 1 + Div 2 Combined) Partial Solution

从这里开始

  • 题目列表
  • 瞎扯
  • Problem A Doggo Recoloring
  • Problem B Weakened Common Divisor
  • Problem C Plasticine zebra
  • Problem D Recovering BST
  • Problem E Colored Cubes
  • Problem F Disjoint Triangles
  • Problem G Company Acquisitions

瞎扯

  打比赛,发现自己特别菜。

  居然还苟且水上紫名

  这个号不敢玩了。要努力学习才能对得起紫名啊,不然再玩两场就灰了。

  然后日常瞎扯一下比赛状况。比如奇葩的AC顺序:A->D->B->C。

  为啥B题分辣么低?Wrong Answer -(发现自己犯傻)-> Pretests Passed -(发现严重bug)-> Resubmission

  C居然数组开小1倍RE了一次,白白丢50分。

  由于做出B的时间有点晚,Hack的机会被Room里一个1小时做不动题的Master全抢走了(好吧,其实是有些人代码看不懂)

  最开始看完B没有一眼切,后来AC的时候还想复杂了qwq。

  只能切完D稳定情绪再回来做。

  然后吐槽一下比赛吧。

  System Test 前 rk 300+,System Test 后 rk 200+。

  为啥?看一下Room里的情况:

  fst + hack专场?

  (mcfx差点rk 1)。

  F好像是bzoj某道合宿题的简化版(看完题解觉得好水。。怪不得OwenOwl一直说这次F好水,好后悔没来打。dream_maker同学说他会$O(n^3)$,不会$O(n^2\log n)$,我很想喷一句。。),E可以用神奇的构造过掉。G?修说是神仙题。

  (最近可能有点忙,坑填得会很慢)

Problem A Doggo Recoloring

题目大意

  给定一个只包含小写字母的字符串,每次可以将一种至少出现了2次的字符都变成另一个字符。问是否可能使所有字符一样。

  特判$n = 1$的时候。其他时候看有没有一个字符出现了两次。

Code

 1 /**
 2  * Codeforces
 3  * Problem#1025D
 4  * Accepted
 5  * Time: 31ms
 6  * Memory: 100k
 7  */
 8 #include <bits/stdc++.h>
 9 using namespace std;
10 typedef bool boolean;
11
12 const int N = 1e5 + 5;
13
14 int n;
15 char str[N];
16 boolean aflag = false;
17 boolean vis[30];
18
19 int main() {
20     scanf("%d", &n);
21     scanf("%s", str);
22     if (n == 1) {
23         puts("YES");
24         return 0;
25     }
26     for (int i = 0; i < n; i++)
27         if (vis[str[i] - ‘a‘]) {
28             puts("YES");
29             return 0;
30         } else
31             vis[str[i] - ‘a‘] = true;
32     puts("NO");
33     return 0;
34 }

Problem A

Problem B Weakened Common Divisor

题目大意

  给定$n$个二元组$(a_{i}, b_{i})$,问是否存在一个$d > 1$,使得对于每个$1\leqslant i \leqslant n$满足$d \mid a_{i}$或者$d \mid b_{i}$。

  首先讲一个沙雕做法。

  暴力枚举$a_{1} \times b_{1}$的质因子。然后$O(n)$检查。时间复杂度$O(\sqrt{V} + n\log{V})$。

  然后讲考场上我的zz做法。

  如果$d$满足条件,那么$d$能够整除$lcm(a_{i}, b_{i})$。就是说$d$能整除每一对的最小公倍数的最大公约数。

  然后找它较小的约数就是答案(因为上面那句话只是必要条件,但不是充分条件,比如可能$d > a_{i}$且$d > b_{i}$,但$d\mid a_{i}b_{i}$)。(少了这一步 WA * 1)

  找这个合法的约数不能暴力找(然后暴力找能过pretest,后来发现resubmission * 1)

  取能成为答案的那部分约数的最小值就好了。这样就可以保证它既是答案,又不会超过任意一个被选中的$a_{i}$或$b_{i}$。

Code

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4
 5 const int N = 150005;
 6
 7 int n;
 8 int a[N], b[N];
 9 ll ls[N];
10
11 ll gcd(ll a, ll b) {
12     return (!b) ? (a) : (gcd(b, a % b));
13 }
14
15 int main(){
16     scanf("%d", &n);
17
18     for (int i = 1; i <= n; i++)
19         scanf("%d%d", a + i, b + i);
20
21     for (int i = 1; i <= n; i++)
22         ls[i] = a[i] / gcd(a[i], b[i]) * b[i];
23     ll res = ls[1];
24
25     for (int i = 2; i <= n; i++)
26         res = gcd(res, ls[i]);
27     for (int i = 1; i <= n; i++) {
28         ll x = gcd(res, a[i]);
29         if (x > 1)
30             res = min(res, x);
31         ll y = gcd(res, b[i]);
32         if (y > 1)
33             res = min(res, y);
34     }
35
36     if (res == 1)
37         cout << -1;
38     else
39         cout << res;
40     return 0;
41 }

Problem B

原文地址:https://www.cnblogs.com/yyf0309/p/9520773.html

时间: 2024-10-26 19:35:21

Codeforces Round #505 (Div 1 + Div 2 Combined) Partial Solution的相关文章

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Codeforces Round #503 (by SIS, Div. 2)

Codeforces Round #503 (by SIS, Div. 2) https://codeforces.com/contest/1020 A 1 #include <iostream> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <s

Educational Codeforces Round 62 (Rated for Div. 2)

layout: post title: Educational Codeforces Round 62 (Rated for Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - dp --- " target="_blank" style="font-size:24px;">传送门 D - Minimum Triangulat

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks