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的时候,最大值肯定能被"独立出来",则直接输出最 ...
随机推荐
- webstorm中es6语法报错,.vue文件中es6语法报错
1.webstorm中es6语法报错,解决方法: 打开 Settings => Languages & Frameworks => Javascript把 Javascript L ...
- Web开发技术选型之Java与PHP
PHP与J2EE的对比 网上有很多关于PHP与J2EE之间的对比,细观无非以下几点: 1.语言特征 PHP为脚本语言,解释型语言,弱类型,专为Web开发打造.Java为C语言系编程语言,编译型,强类型 ...
- C#RabbitMQ基础学习笔记
RabbitMQ基础学习笔记(C#代码示例) 一.定义: MQ是MessageQueue,消息队列的简称(是流行的开源消息队列系统,利用erlang语言开发).MQ是一种应用程序对应用程序的通信方法. ...
- jQuery 判断元素上是否绑定了事件
我研究了一下之后发现,jQuery都将事件缓存起来了,其实也是为了防止内存溢出以及页面unload的时候的速度,也包括多函数触发,方便管理等诸多好处,具体可以参考此文. jQuery会在window. ...
- JS实现一位数显示为两位
使用js脚本实现页面一位数字显示为两位,不足两位前面加“0”. function fix(num, length) { return ('' + num).length < length ? ( ...
- [linux] shell脚本编程-xunsearch安装脚本学习
安装脚本setup.sh #!/bin/sh # FULL fast install/upgrade script # See help message via `--help' # $Id$ # s ...
- 深入理解Java线程池:ScheduledThreadPoolExecutor
介绍 自JDK1.5开始,JDK提供了ScheduledThreadPoolExecutor类来支持周期性任务的调度.在这之前的实现需要依靠Timer和TimerTask或者其它第三方工具来完成.但T ...
- windbg .net 程序的死锁检测 常用方法(个人备份笔记)
//死锁检测 .load sosex.dll :> !dlk :> !mk -a The mk command displays a call stack of the currently ...
- Oracle数据库基本操作(四) —— PLSQL编程
Procedure Language 实际上是Oracle对SQL语言的能力扩展,让SQL语言拥有了if条件判断,for循环等处理. 一.PLSQL基本语法 DECLARE -- 声明部分 变量名 变 ...
- 利用localStorage事件来跨标签页共享sessionStorage
//干货 利用localStorage事件来跨标签页共享sessionStorage //因为cookie保存字节数量有限,很多童鞋考虑用html5 storage来保存临时数据,Sessionsto ...