题目戳这里

A.A Serial Killer

题目描述似乎很恶心,结合样例和样例解释猜测的题意

使用C++11的auto可以来一手骚操作

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. string s[];
  8.  
  9. map <string, int> p;
  10.  
  11. int main() {
  12. cin >> s[] >> s[];
  13. p[s[]] = p[s[]] = ;
  14. cin >> n;
  15. cout << s[] << " " <<s[] << endl;
  16. while(n --) {
  17. cin >> s[] >> s[];
  18. p[s[]] ++, p[s[]] ++;
  19. for(auto iter : p)
  20. if(iter.second == ) cout << iter.first << " ";
  21. puts("");
  22. }
  23. return ;
  24. }

其实等价于这样写

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. string s[];
  8.  
  9. map <string, int> p;
  10.  
  11. int main() {
  12. cin >> s[] >> s[];
  13. p[s[]] = p[s[]] = ;
  14. cin >> n;
  15. cout << s[] << " " <<s[] << endl;
  16. while(n --) {
  17. cin >> s[] >> s[];
  18. p[s[]] ++, p[s[]] ++;
  19. for(map <string, int>::iterator iter = p.begin();iter != p.end();iter ++)
  20. if(iter -> second == ) cout << iter -> first << " ";
  21. puts("");
  22. }
  23. return ;
  24. }

B.Sherlock and his girlfriend

很蠢的一题,质数标1,合数标2就好了

  1. #include <bits/stdc++.h>
  2.  
  3. #define rep(i, j, k) for(int i = j;i <= k;i ++)
  4.  
  5. #define rev(i, j, k) for(int i = j;i >= k;i --)
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. const int maxn = ;
  12.  
  13. int n, a[maxn];
  14.  
  15. int main() {
  16. ios::sync_with_stdio(false);
  17. cin >> n;
  18. if(n < ) puts("");
  19. else puts("");
  20. for(int i = ;i <= n + ;i ++)
  21. if(a[i] != ) {
  22. a[i] = ;
  23. for(int j = i << ;j <= n + ;j += i)
  24. a[j] = ;
  25. }
  26. for(int i = ;i <= n + ;i ++)
  27. printf("%d ", a[i]);
  28. return ;
  29. }

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 特判,否则死循环

  1. #include <bits/stdc++.h>
  2.  
  3. #define rep(i, j, k) for(int i = j;i <= k;i ++)
  4.  
  5. #define rev(i, j, k) for(int i = j;i >= k;i --)
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. int n, t;
  12.  
  13. ll k, s[];
  14.  
  15. map <ll, int> p;
  16.  
  17. int main() {
  18. ios::sync_with_stdio(false);
  19. int x;
  20. cin >> n >> t;
  21. rep(i, , n) cin >> x, s[i] = s[i - ] + x;
  22. for(ll j = ;abs(j) <= 100000000000000ll;j *= t) {
  23. p.clear(), p[] = ;
  24. rep(i, , n) {
  25. k += p[s[i] - j];
  26. p[s[i]] ++;
  27. }
  28. if(t == || (t == - && j == -)) break;
  29. }
  30. cout << k;
  31. return ;
  32. }

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

直接并查集就可以解决了

  1. #include <cstdio>
  2.  
  3. const int maxn = ;
  4.  
  5. int n, m, f[maxn << ], a[][maxn];
  6.  
  7. bool op[maxn];
  8.  
  9. int find_(int x) {
  10. if(f[x] != x) return f[x] = find_(f[x]);
  11. return x;
  12. }
  13.  
  14. void union_(int x, int y) {
  15. x = find_(x), y = find_(y);
  16. if(x != y) f[x] = y;
  17. }
  18.  
  19. int main() {
  20. scanf("%d %d", &n, &m);
  21. for(int i = ;i <= n;i ++) scanf("%d", &op[i]);
  22. for(int k, j, i = ;i <= m;i ++) {
  23. scanf("%d", &j);
  24. while(j --) {
  25. scanf("%d", &k);
  26. if(a[][k]) a[][k] = i;
  27. else a[][k] = i;
  28. }
  29. }
  30. for(int i = m << ;i;i --) f[i] = i;
  31. for(int i = ;i <= n;i ++)
  32. if(op[i]) union_(a[][i], a[][i]), union_(a[][i] + m, a[][i] + m);
  33. else union_(a[][i], a[][i] + m), union_(a[][i] + m, a[][i]);
  34. for(int i = ;i <= m;i ++)
  35. if(find_(i) == find_(i + m)) {
  36. puts("NO");
  37. return ;
  38. }
  39. puts("YES");
  40. return ;
  41. }

E.The Holmes Children

手动计算发现 f 函数为欧拉函数

gcd(x, y) = 1

x + y = n

=> gcd(x, x + y) = 1 即 gcd(x, n) = 1

g(n) = n ,剩下部分很好解决

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. const int mod_ = 1e9 + ;
  8.  
  9. ll f(ll x) {
  10. ll ret = x;
  11. for(ll i = ;i * i <= x;i ++)
  12. if(x % i == ) {
  13. ret /= i, ret *= (i - );
  14. while(x % i == ) x /= i;
  15. }
  16. if(x != ) ret /= x, ret *= (x - );
  17. return ret;
  18. }
  19.  
  20. int main(){
  21. ll n, k;
  22. cin >> n >> k;
  23. k = (k + ) >> ;
  24. for(int i = ;i <= k;i ++) {
  25. n = f(n);
  26. if(n == ) break;
  27. }
  28. cout << n % mod_;
  29. return ;
  30. }

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. canvas上的像素操作(图像复制,细调)

    canvas上的像素操作(图像复制,细调) 总结 1.操作对象:ImageData 对象,其实是canvas的像素点集合 2.主要操作: var obj=ctx.getImageData(0,0,10 ...

  2. 如何在vue项目中引入阿里巴巴的iconfont图库

    1. 打开 http://www.iconfont.cn/ 2. 选择我们喜欢的图标,点击上面的小车,加入图标库,即右侧的购物车 3.点击购物车,点击下载代码 4.解压下载的文件夹,将文件夹复制到 a ...

  3. WP处理事件

    (1).Launching事件 Launching(进入)事件是每一个第三方应用在第一次运行时都必须执行的事件,它主要负责应用程序的初始化.这个事件与Closing事件是对应的,一个运行正常的应用程序 ...

  4. 尝试安卓与js交互

    1.android中利用webview调用网页上的js代码. Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设置为true ...

  5. python导入包出错:ImportError: No module named XXXXX

    python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包.只要模块或者包所在的目录在sys.path中,就可以使用import 模块或import 包来使用. 如果想 ...

  6. MySql(二):常见的那些个约束

    今天总结一下mysql当中的常见约束吧! 那什么是约束呢?通俗点讲,约束就是限定指定字段的存放规则! ● 主键约束(Primary Key) ● 外键约束(Foreign Key) ● 非空约束(No ...

  7. WinForm窗体项目 之 MySchool管理系统终极版

    学习WinForm窗体程序也有一段时间了,今天就来尝试着来一个项目热热身~ 在我们通常使用的MySchool管理中,不外乎这几种功能:增.删.改.查.改密码 在过去的C#中确实是挺简单的,但是在学习了 ...

  8. 【转】Java 集合系列11之 Hashtable详细介绍(源码解析)和使用示例

    概要 前一章,我们学习了HashMap.这一章,我们对Hashtable进行学习.我们先对Hashtable有个整体认识,然后再学习它的源码,最后再通过实例来学会使用Hashtable.第1部分 Ha ...

  9. canvas烟花锦集

    canvas可以实现不同动画效果,本文主要记录几种不同节日烟花效果实现. 实现一 效果地址 html <canvas id="canvas"></canvas&g ...

  10. Ajax——瀑布流

    基本概念 1.宽度是一致的,高度上参差不齐 2.新增内容优先放置在最矮的地方 核心难点 1.用一个数组存储每列的高度值 2.新值添加到值最小索引上,每次替换更新数组 插件使用 1.$.fn.exten ...