题目戳这里

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. 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 ...

  6. 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 ...

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

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. 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 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

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

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. Spring -> Spring Boot > Spring Cloud

    这几天刚刚上班,公司用的是Spring Cloud,接触不多.我得赶快学起来. 想学习就必须得知道什么是微服务,什么是Spring Boot,什么是Spring Cloud,以及两者之间有什么关系? ...

  2. Olddriver’s books

    Olddriver 的书多的吓人,什么算法导论,组合数学英 文版(orz)......他把 n 本书都放在身后的桌子上, 每本书有一定的面积,并且书可以覆盖,求 n 本书覆盖桌面 的面积 输入格式: ...

  3. Ubuntu下FileZilla的安装(转载)

    转自:http://os.51cto.com/art/201103/247564.htm FileZilla是一个免费而且开源的FTP客户端软件,共有两种版本:客户端版本.服务器版本.FileZill ...

  4. AbstractRoutingDataSource动态选择数据源

    当我们项目变大后,有时候需要多个数据源,接下来我们讲一种能等动态切换数据源的例子. 盗一下图: 单数据源的场景(一般的Web项目工程这样配置进行处理,就已经比较能够满足我们的业务需求) 多数据源多Se ...

  5. PCB MS SQL 标量函数(CLR) 实现Socket发送消息

    在PCB业务系统中,数据库中的数据总是被应用端主动连接数据库并操作数据,是否想过可以让数据库主动的将数据推送出去呢! 答应其实是可以的.比如有这样的应用场景! 当SQL SERVER数据库满足某个条件 ...

  6. PCB 规则引擎之JSON对象查看器

    在PCB规则引擎开发中,JavaScript V8引擎是处理业务逻辑的, 当然业务逻辑需要数据支撑才行,  即需有将数据推进入到V8引擎.目前这边数据传输到JavaScript V8引擎以C# Mod ...

  7. Rails 拉数据初始数据库

    rails c   [1] pry(main)> Scraping.exec

  8. Mysql中date,time,datetime,timestamp的区别

    区别: timestamp:时间戳.北京时间1970年01月01日08时00分00秒 起至现在的总秒数. datetime:带时分秒的完整时间,例如:1970-01-01 10:00:00 date: ...

  9. 关于 node.js 小插曲

    随着web2.0的时代到来,javascript在前端担任了更多的职责,事件也看得到了广泛的应用,node不像rhino那样受java的影响很大,而是将前端浏览器中应用广泛企鹅成熟的事件引入后端,配合 ...

  10. 数据库部署到linux服务器,供本地访问。

    1.  将本地的sql文件上传至服务器 scp /Users/fangke/Documents/article.sql root@IP:/usr/local 2. 登陆服务器的mysql 3. 创建数 ...