Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2)
codeforces 870 A. Search for Pretty Integers(水题)
题意:给两个数组,求一个最小的数包含两个数组各至少一个数。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- int n, m;
- int a[], b[];
- int main() {
- int i, j, x = , y = , s = ;
- scanf("%d%d", &n, &m);
- for(i = ; i <= n; ++i) {
- scanf("%d", &a[i]); if(a[i] < x) x = a[i];
- }
- for(i = ; i <= m; ++i) {
- scanf("%d", &b[i]); if(b[i] < y) y = b[i];
- for(j = ; j <= n; ++j)
- if(a[j] == b[i] && b[i] < s) s = b[i];
- }
- if(s < ) printf("%d\n", s);
- else {
- if(x > y) swap(x, y);
- printf("%d%d\n", x, y);
- }
- return ;
- }
31ms
codeforces 870 B. Maximum of Maximums of Minimums(模拟)
题意:给一排N个数,要求分割成K份,每份里面取出最小的数,再从取出的这些数中求最大的数,,求能得到的最大的数。
题解:K=1时答案即为最小的数,K≥3时,答案为这排数中最大的数,K=2时,就是两端 两个数的最大的一个。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- const int N = ;
- int n, m;
- int a[N];
- int main() {
- int i, j, mi = , ma = -;
- scanf("%d%d", &n, &m);
- for(i = ; i <= n; ++i) {
- scanf("%d", &a[i]);
- if(a[i] < mi) mi = a[i];
- if(a[i] > ma) ma = a[i];
- }
- if(m==) printf("%d\n", mi);
- else if(m==) printf("%d\n", max(a[], a[n]));
- else printf("%d\n", ma);
- return ;
- }
31ms
codeforces 870 C. Maximum splitting(数学)
题意:一个数拆分成几个合数之和,求最多能拆分成几个数之和。
题解:合数为4,6,9最优咯。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- int main() {
- int t, n;
- scanf("%d", &t);
- while(t--) {
- scanf("%d", &n);
- int ans = ;
- if(n & ) {
- n -=; ans++;
- }
- if(n < && n != ) puts("-1");
- else {
- ans += n/;
- printf("%d\n", ans);
- }
- }
- return ;
- }
61ms
codeforces 870 E. Points, Lines and Ready-made Titles(思维)
题意:对每个点,可以绘制一条垂直线,或一条水平线,或什么都不做。几条重合的直线是一条直线,求可以得到多少个不同的图片。
题解:排序,将同一行的用并查集合并,再将同一列的也合并,假设一个集合的点在原图的不重复行列数为s,如果该集合的点在原图中不能形成环,则该集合的贡献是2^s-1(少一种是环的图形),否则贡献为2^s。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- typedef long long ll;
- const int N = ;
- const ll mod = 1e9+;
- int f[N], r1[N], r2[N];
- struct node {
- int x, y, id;
- }p[N];
- int cmp1(node a, node b) {return a.x < b.x;}
- int cmp2(node a, node b) {return a.y < b.y;}
- int fin(int x) {
- if(f[x]!=x) f[x] = fin(f[x]);
- return f[x];
- }
- void uni(int x, int y) {
- if((x=fin(x)) == (y=fin(y))) r2[y]++;
- else {
- f[x] = y;
- r1[y] += r1[x];
- r2[y] += r2[x] + ;
- }
- }
- int main() {
- int n, i, j;
- ll ans = ;
- ll a[*N]; a[] = 1ll;
- for(i = ; i < *N; ++i) a[i] = (a[i-] * ) % mod;
- scanf("%d", &n);
- memset(r2, , sizeof(r2));
- for(i = ; i <= n; ++i) {
- scanf("%d%d", &p[i].x, &p[i].y);
- p[i].id = i;
- f[i] = i;
- r1[i] = ;
- }
- sort(p+, p++n, cmp1);
- for(i = ; i <= n; ++i)
- if(p[i].x == p[i-].x) uni(p[i].id, p[i-].id);
- sort(p+, p++n, cmp2);
- for(i = ; i <= n; ++i)
- if(p[i].y == p[i-].y) uni(p[i].id, p[i-].id);
- for(i = ; i <= n; ++i)
- if(f[i] == i) {
- if(r1[i] == r2[i]+) ans = ans * (ll)(a[r1[i]+] - ) % mod;
- else ans = ans * (ll)(a[*r1[i] - r2[i]]) % mod;
- }
- printf("%lld\n", ans);
- return ;
- }
93ms
Codeforces Round #440 (Div. 2)【A、B、C、E】的更多相关文章
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- 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. 题解:答案就是 ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- 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.直接暴力判断即 ...
- 【Codeforces Round #440 (Div. 2) C】 Maximum splitting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定用尽量多的4最好. 然后对4取模的结果 为0,1,2,3分类讨论即可 [代码] #include <bits/stdc++ ...
- 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k=1的时候就是最小值, k=2的时候,暴力枚举分割点. k=3的时候,最大值肯定能被"独立出来",则直接输出最 ...
随机推荐
- android studio导入android studio工程
在导入其他android studio工程的时候因为gradle和sdk.tool等版本不一样,会导致android studio自动去后台下载,导致占用硬盘越来越大,最主要的时候会等待很久,不知道要 ...
- Node.js模块封装及使用
Node.js中也有一些功能的封装,类似C#的类库,封装成模块这样方便使用,安装之后用require()就能引入调用. 一.Node.js模块封装 1.创建一个名为censorify的文件夹 2.在c ...
- 第4章 scrapy爬取知名技术文章网站(2)
4-8~9 编写spider爬取jobbole的所有文章 # -*- coding: utf-8 -*- import re import scrapy import datetime from sc ...
- Vue2.0学习笔记:Vue事件修饰符的使用
事件处理 如果需要在内联语句处理器中访问原生DOM事件.可以使用特殊变量$event,把它传入到methods中的方法中. 在Vue中,事件修饰符处理了许多DOM事件的细节,让我们不再需要花大量的时间 ...
- Vue 2.0的学习笔记:Vue的过滤器
转自: https://www.w3cplus.com/vue/how-to-create-filters-in-vuejs.html 过滤器的介绍 1.在Vue中使用过滤器(Filters)来渲染数 ...
- JAVA注释方式
1.单行(single-line)注释 //…… 2.块(block)注释 /*……*/ 3.文档注释 /**……*/
- vim 编辑器常规操作
所看视频教程:兄弟连Linux云计算视频教程5.1文本编辑器Vim-5.2 插入命令 a:在光标所在字符后插入; A:在光标所在行尾插入; i:在光标所在字符前插入; I:在光标所在字符行行首插入; ...
- Spring学习笔记:spring整合web之spring-web架包的引用(WebApplicationContextUtils注入容器)
WebApplicationContextUtils 一.Spring整合web之前 案例:给部门列表添加新部门 import org.apache.log4j.Logger; import org. ...
- linux下elasticsearch集成mongodb详细教程
由于公司业务需要,要用elasticsearch做索引库实现搜索功能,历尽千辛万苦,最后总算把mongodb和elasticsearch集成成功 1.搭建mongodb集群 参考https://www ...
- python保存字典和读取字典pickle
import pickle import numpy as np def save_obj(obj, name): with open(name + '.pkl', 'wb') as f: pickl ...