Codeforces Round #440 (Div. 2)

codeforces 870 A. Search for Pretty Integers(水题)

题意:给两个数组,求一个最小的数包含两个数组各至少一个数。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. int n, m;
  6. int a[], b[];
  7. int main() {
  8. int i, j, x = , y = , s = ;
  9. scanf("%d%d", &n, &m);
  10. for(i = ; i <= n; ++i) {
  11. scanf("%d", &a[i]); if(a[i] < x) x = a[i];
  12. }
  13. for(i = ; i <= m; ++i) {
  14. scanf("%d", &b[i]); if(b[i] < y) y = b[i];
  15. for(j = ; j <= n; ++j)
  16. if(a[j] == b[i] && b[i] < s) s = b[i];
  17. }
  18. if(s < ) printf("%d\n", s);
  19. else {
  20. if(x > y) swap(x, y);
  21. printf("%d%d\n", x, y);
  22. }
  23. return ;
  24. }

31ms

codeforces 870 B. Maximum of Maximums of Minimums(模拟)

题意:给一排N个数,要求分割成K份,每份里面取出最小的数,再从取出的这些数中求最大的数,,求能得到的最大的数。

题解:K=1时答案即为最小的数,K≥3时,答案为这排数中最大的数,K=2时,就是两端 两个数的最大的一个。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N = ;
  6. int n, m;
  7. int a[N];
  8. int main() {
  9. int i, j, mi = , ma = -;
  10. scanf("%d%d", &n, &m);
  11. for(i = ; i <= n; ++i) {
  12. scanf("%d", &a[i]);
  13. if(a[i] < mi) mi = a[i];
  14. if(a[i] > ma) ma = a[i];
  15. }
  16. if(m==) printf("%d\n", mi);
  17. else if(m==) printf("%d\n", max(a[], a[n]));
  18. else printf("%d\n", ma);
  19. return ;
  20. }

31ms

codeforces 870 C. Maximum splitting(数学)

题意:一个数拆分成几个合数之和,求最多能拆分成几个数之和。

题解:合数为4,6,9最优咯。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. int main() {
  6. int t, n;
  7. scanf("%d", &t);
  8. while(t--) {
  9. scanf("%d", &n);
  10. int ans = ;
  11. if(n & ) {
  12. n -=; ans++;
  13. }
  14. if(n < && n != ) puts("-1");
  15. else {
  16. ans += n/;
  17. printf("%d\n", ans);
  18. }
  19. }
  20. return ;
  21. }

61ms

codeforces 870 E. Points, Lines and Ready-made Titles(思维)

题意:对每个点,可以绘制一条垂直线,或一条水平线,或什么都不做。几条重合的直线是一条直线,求可以得到多少个不同的图片。

题解:排序,将同一行的用并查集合并,再将同一列的也合并,假设一个集合的点在原图的不重复行列数为s,如果该集合的点在原图中不能形成环,则该集合的贡献是2^s-1(少一种是环的图形),否则贡献为2^s。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. typedef long long ll;
  6. const int N = ;
  7. const ll mod = 1e9+;
  8. int f[N], r1[N], r2[N];
  9. struct node {
  10. int x, y, id;
  11. }p[N];
  12. int cmp1(node a, node b) {return a.x < b.x;}
  13. int cmp2(node a, node b) {return a.y < b.y;}
  14. int fin(int x) {
  15. if(f[x]!=x) f[x] = fin(f[x]);
  16. return f[x];
  17. }
  18. void uni(int x, int y) {
  19. if((x=fin(x)) == (y=fin(y))) r2[y]++;
  20. else {
  21. f[x] = y;
  22. r1[y] += r1[x];
  23. r2[y] += r2[x] + ;
  24. }
  25. }
  26. int main() {
  27. int n, i, j;
  28. ll ans = ;
  29. ll a[*N]; a[] = 1ll;
  30. for(i = ; i < *N; ++i) a[i] = (a[i-] * ) % mod;
  31. scanf("%d", &n);
  32. memset(r2, , sizeof(r2));
  33. for(i = ; i <= n; ++i) {
  34. scanf("%d%d", &p[i].x, &p[i].y);
  35. p[i].id = i;
  36. f[i] = i;
  37. r1[i] = ;
  38. }
  39. sort(p+, p++n, cmp1);
  40. for(i = ; i <= n; ++i)
  41. if(p[i].x == p[i-].x) uni(p[i].id, p[i-].id);
  42. sort(p+, p++n, cmp2);
  43. for(i = ; i <= n; ++i)
  44. if(p[i].y == p[i-].y) uni(p[i].id, p[i-].id);
  45.  
  46. for(i = ; i <= n; ++i)
  47. if(f[i] == i) {
  48. if(r1[i] == r2[i]+) ans = ans * (ll)(a[r1[i]+] - ) % mod;
  49. else ans = ans * (ll)(a[*r1[i] - r2[i]]) % mod;
  50. }
  51. printf("%lld\n", ans);
  52. return ;
  53. }

93ms

Codeforces Round #440 (Div. 2)【A、B、C、E】的更多相关文章

  1. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  2. Codeforces Round #434 (Div. 2)【A、B、C、D】

    Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...

  3. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  4. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  5. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  6. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  7. Codeforces Round #430 (Div. 2) 【A、B、C、D题】

    [感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...

  8. 【Codeforces Round #440 (Div. 2) C】 Maximum splitting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定用尽量多的4最好. 然后对4取模的结果 为0,1,2,3分类讨论即可 [代码] #include <bits/stdc++ ...

  9. 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k=1的时候就是最小值, k=2的时候,暴力枚举分割点. k=3的时候,最大值肯定能被"独立出来",则直接输出最 ...

随机推荐

  1. android studio导入android studio工程

    在导入其他android studio工程的时候因为gradle和sdk.tool等版本不一样,会导致android studio自动去后台下载,导致占用硬盘越来越大,最主要的时候会等待很久,不知道要 ...

  2. Node.js模块封装及使用

    Node.js中也有一些功能的封装,类似C#的类库,封装成模块这样方便使用,安装之后用require()就能引入调用. 一.Node.js模块封装 1.创建一个名为censorify的文件夹 2.在c ...

  3. 第4章 scrapy爬取知名技术文章网站(2)

    4-8~9 编写spider爬取jobbole的所有文章 # -*- coding: utf-8 -*- import re import scrapy import datetime from sc ...

  4. Vue2.0学习笔记:Vue事件修饰符的使用

    事件处理 如果需要在内联语句处理器中访问原生DOM事件.可以使用特殊变量$event,把它传入到methods中的方法中. 在Vue中,事件修饰符处理了许多DOM事件的细节,让我们不再需要花大量的时间 ...

  5. Vue 2.0的学习笔记:Vue的过滤器

    转自: https://www.w3cplus.com/vue/how-to-create-filters-in-vuejs.html 过滤器的介绍 1.在Vue中使用过滤器(Filters)来渲染数 ...

  6. JAVA注释方式

    1.单行(single-line)注释    //…… 2.块(block)注释                /*……*/ 3.文档注释                      /**……*/

  7. vim 编辑器常规操作

    所看视频教程:兄弟连Linux云计算视频教程5.1文本编辑器Vim-5.2 插入命令 a:在光标所在字符后插入; A:在光标所在行尾插入; i:在光标所在字符前插入; I:在光标所在字符行行首插入; ...

  8. Spring学习笔记:spring整合web之spring-web架包的引用(WebApplicationContextUtils注入容器)

    WebApplicationContextUtils 一.Spring整合web之前 案例:给部门列表添加新部门 import org.apache.log4j.Logger; import org. ...

  9. linux下elasticsearch集成mongodb详细教程

    由于公司业务需要,要用elasticsearch做索引库实现搜索功能,历尽千辛万苦,最后总算把mongodb和elasticsearch集成成功 1.搭建mongodb集群 参考https://www ...

  10. python保存字典和读取字典pickle

    import pickle import numpy as np def save_obj(obj, name): with open(name + '.pkl', 'wb') as f: pickl ...