「CF1220X」Codeforces Round #586
A. Cards
统计一下 z 和 o 的个数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define pa pair<int,int> #define ll long long #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; string s; map<char, int> mp; int main() { cin >> n >> s; for(int i = 0; i < n; i++) mp[s[i]]++; while(mp['n']) { mp['n']--; mp['o']--; cout << 1 << ' '; } while(mp['o']) { mp['o']--; cout << 0 << ' '; } return 0; } |
B. Multiplication Table
取第一行的 gcd,则 a1 一定是 gcd 的约数
再取一个 M23,确定一下 a1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define pa pair<int,int> #define ll long long #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int gcd(int a, int b) { return b == 0? a : gcd(b, a % b); } int n; ll a[1005][1005], b[1005]; int main() { n = read(); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) a[i][j] = read(); int p = 0; for(int i = 1; i <= n; i++) p = gcd(p, a[1][i]); for(int i = 2; i <= n; i++) b[i] = a[1][i] / p; if(b[2] * b[3] != a[2][3]) { int q = (int)sqrt(a[2][3] / b[2] / b[3]); p = p / q; } printf("%d ", p); for(int i = 2; i <= n; i++) printf("%I64d ", a[1][i] / p); return 0; } |
C. Substring Game in the Lesson
先手可以直接转移到左边的最小字符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define pa pair<int,int> #define ll long long #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } string s; int main() { cin >> s; int mn = 100; for(int i = 0; i < s.length(); i++) { if(s[i] - 'a' > mn) puts("Ann"); else puts("Mike"); mn = min(mn, s[i] - 'a'); } return 0; } |
D. Alex and Julian
按每个数的 2 的因子数分类,只有 2 的因子数相同的才能共存
选择最多数的一类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define pa pair<int,int> #define ll long long #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n, mx, v; ll b[200005], a[200005]; int cnt[105]; int main() { n = read(); for(int i = 1; i <= n; i++) b[i] = read(); for(int i = 1; i <= n; i++) { ll tmp = 2; while(b[i] % tmp == 0) { tmp *= 2; a[i]++; } cnt[a[i]]++; if(cnt[a[i]] > mx) { mx = cnt[a[i]]; v = a[i]; } } printf("%d\n", n - mx); for(int i = 1; i <= n; i++) if(a[i] != v) printf("%I64d ", b[i]); return 0; } |
E. Tourism
按起点为根建树,如果某个点出发有非树边,意味着可以从起点到它再回到起点,把这条链都打上标记
最后所有带标记的点,是包含起点的一个连通块,再树形 dp 找出连通块外的一条最长链,答案就是连通块权值和加最长链
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define pa pair<int,int> #define ll long long #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n, m, s; int w[200005], fa[200005], ufa[200005], vis[200005]; ll f[200005]; vector<int> e[200005]; bool d[200005]; void del(int x) { if(x == s || d[x])return; d[x] = 1; del(fa[x]); } void dfs(int x) { vis[x] = 1; bool mark = 0; f[x] = w[x]; for(int i = 0; i < e[x].size(); i++) if(!vis[e[x][i]]) { fa[e[x][i]] = x; dfs(e[x][i]); f[x] = max(f[x], f[e[x][i]] + w[x]); } else if(e[x][i] != fa[x] || mark == 1) { del(x); del(e[x][i]); } else mark = 1; } int main() { n = read(); m = read(); for(int i = 1; i <= n; i++) ufa[i] = i; for(int i = 1; i <= n; i++) w[i] = read(); for(int i = 1; i <= m; i++) { int u = read(), v = read(); e[u].push_back(v); e[v].push_back(u); } s = read(); dfs(s); d[s] = 1; ll ans1 = 0, ans2 = 0; for(int i = 1; i <= n; i++) { if(d[i]) ans1 += w[i]; else ans2 = max(ans2, f[i]); } cout << ans1 + ans2 << endl; return 0; } |
Subscribe