Codeforces Round #400 (Div. 1 + Div. 2, combined)——ABCDE
题目戳这里
A.A Serial Killer
题目描述似乎很恶心,结合样例和样例解释猜测的题意
使用C++11的auto可以来一手骚操作
#include <bits/stdc++.h> using namespace std; int n; string s[]; map <string, int> p; int main() {
cin >> s[] >> s[];
p[s[]] = p[s[]] = ;
cin >> n;
cout << s[] << " " <<s[] << endl;
while(n --) {
cin >> s[] >> s[];
p[s[]] ++, p[s[]] ++;
for(auto iter : p)
if(iter.second == ) cout << iter.first << " ";
puts("");
}
return ;
}
其实等价于这样写
#include <bits/stdc++.h> using namespace std; int n; string s[]; map <string, int> p; int main() {
cin >> s[] >> s[];
p[s[]] = p[s[]] = ;
cin >> n;
cout << s[] << " " <<s[] << endl;
while(n --) {
cin >> s[] >> s[];
p[s[]] ++, p[s[]] ++;
for(map <string, int>::iterator iter = p.begin();iter != p.end();iter ++)
if(iter -> second == ) cout << iter -> first << " ";
puts("");
}
return ;
}
B.Sherlock and his girlfriend
很蠢的一题,质数标1,合数标2就好了
#include <bits/stdc++.h> #define rep(i, j, k) for(int i = j;i <= k;i ++) #define rev(i, j, k) for(int i = j;i >= k;i --) using namespace std; typedef long long ll; const int maxn = ; int n, a[maxn]; int main() {
ios::sync_with_stdio(false);
cin >> n;
if(n < ) puts("");
else puts("");
for(int i = ;i <= n + ;i ++)
if(a[i] != ) {
a[i] = ;
for(int j = i << ;j <= n + ;j += i)
a[j] = ;
}
for(int i = ;i <= n + ;i ++)
printf("%d ", a[i]);
return ;
}
C.Molly's Chemicals
有那么一点意思的题目
求有多少段连续子段和为k的非负power
显然k为2的话,大概能2^0 - 2^50左右吧
所以直接枚举 k^p 即可
偷懒套个map,复杂度O(n(logn)^2)
注意:
1.非负power,包括1
2. |k| = 1 特判,否则死循环
#include <bits/stdc++.h> #define rep(i, j, k) for(int i = j;i <= k;i ++) #define rev(i, j, k) for(int i = j;i >= k;i --) using namespace std; typedef long long ll; int n, t; ll k, s[]; map <ll, int> p; int main() {
ios::sync_with_stdio(false);
int x;
cin >> n >> t;
rep(i, , n) cin >> x, s[i] = s[i - ] + x;
for(ll j = ;abs(j) <= 100000000000000ll;j *= t) {
p.clear(), p[] = ;
rep(i, , n) {
k += p[s[i] - j];
p[s[i]] ++;
}
if(t == || (t == - && j == -)) break;
}
cout << k;
return ;
}
D.The Door Problem
应该注意到each door is controlled by exactly two switches
所以显然对于一开始锁上的门,只能选择一个开关
一开始打开的门,可以选择都不选或者都选
于是我们可以想到2-sat来解决
实际上2-sat也的确可以解决
但是我们注意到这个2-sat的特殊性
每组中的两个选择在某种程度上是等价的
而我们平时做的 Ai 与 Ai’ 是不等价的
两个选择等价意味着连的边已经是无向边
即若有Ai -> Aj,则必有Aj -> Ai
这样就不需要再tarjan
直接并查集就可以解决了
#include <cstdio> const int maxn = ; int n, m, f[maxn << ], a[][maxn]; bool op[maxn]; int find_(int x) {
if(f[x] != x) return f[x] = find_(f[x]);
return x;
} void union_(int x, int y) {
x = find_(x), y = find_(y);
if(x != y) f[x] = y;
} int main() {
scanf("%d %d", &n, &m);
for(int i = ;i <= n;i ++) scanf("%d", &op[i]);
for(int k, j, i = ;i <= m;i ++) {
scanf("%d", &j);
while(j --) {
scanf("%d", &k);
if(a[][k]) a[][k] = i;
else a[][k] = i;
}
}
for(int i = m << ;i;i --) f[i] = i;
for(int i = ;i <= n;i ++)
if(op[i]) union_(a[][i], a[][i]), union_(a[][i] + m, a[][i] + m);
else union_(a[][i], a[][i] + m), union_(a[][i] + m, a[][i]);
for(int i = ;i <= m;i ++)
if(find_(i) == find_(i + m)) {
puts("NO");
return ;
}
puts("YES");
return ;
}
E.The Holmes Children
手动计算发现 f 函数为欧拉函数
gcd(x, y) = 1
x + y = n
=> gcd(x, x + y) = 1 即 gcd(x, n) = 1
g(n) = n ,剩下部分很好解决
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod_ = 1e9 + ; ll f(ll x) {
ll ret = x;
for(ll i = ;i * i <= x;i ++)
if(x % i == ) {
ret /= i, ret *= (i - );
while(x % i == ) x /= i;
}
if(x != ) ret /= x, ret *= (x - );
return ret;
} int main(){
ll n, k;
cin >> n >> k;
k = (k + ) >> ;
for(int i = ;i <= k;i ++) {
n = f(n);
if(n == ) break;
}
cout << n % mod_;
return ;
}
Codeforces Round #400 (Div. 1 + Div. 2, combined)——ABCDE的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- 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://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- Bing Maps进阶系列五:通过DeepEarth的MiniMap控件为Bing Maps扩展迷你小地图
Bing Maps进阶系列五:通过DeepEarth的MiniMap控件为Bing Maps扩展迷你小地图 Bing Maps Silverlight Control虽然为我们提供了简洁.方便的开发模 ...
- java四舍五入保留几位小数
double d = 3.1415926; String result = String.format("%.2f", d); // %.2f %. 表示 小数点前任意位数 2 表 ...
- P5058 [ZJOI2004]嗅探器 tarjan割点
这个题是tarjan裸题.最后bfs暴力找联通块就行.(一开始完全写错了竟然得了70分,题意都理解反了...这数据强度...) 题干: 题目描述 某军搞信息对抗实战演习,红军成功地侵入了蓝军的内部网络 ...
- poj3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割水题(竟然没能1A): 代码如下: #include<iostream> #include<cstdio&g ...
- openstack 杂记 备忘002
- 让谷歌浏览器(chrome)保存调试代码workspace
方法/步骤 chrome浏览器早期版本的操作方法与我现在要讲的方法有所不同,因此操作前请注意浏览器的版本号. 示例中的版本号: 53.0.2785.116 m 任意打开一个需要调试的html文件 ...
- 【洛谷1117_BZOJ4650】[NOI2016] 优秀的拆分(哈希_后缀数组_RMQ)
题目: 洛谷1117 分析: 定义把我校某兔姓神犇Tzz和他的妹子拆分,为"优秀的拆分" 随便写个哈希就能有\(95\)分的好成绩-- 我的\(95\)分做法比fei较chang奇 ...
- 设计模式 Singleton 单例 懒汉,线程安全
首先来明确一个问题,那就是在某些情况下,有些对象,我们只需要一个就可以了, 比如,一台计算机上可以连好几个打印机,但是这个计算机上的打印程序只能有一个, 这里就可以通过单例模式来避免两个打印作业同时输 ...
- Linux添加用户组和删除用户组
1.添加用户组使用groupadd命令添加用户组:groupadd group_name此操作需由系统管理员进行.2.删除用户组使用groupdel命令删除用户组:groupdel group_nam ...
- Windows 10 IIS所有的html返回空白
这是一个神奇的现象.因为使用IIS已经有N多年了,喜欢使用它是因为它随手可得.自从装上windows10以来,直至今天才用它来调试客户端程序.想在上面放一个静态的json数据,省的还要去建立一个Web ...