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

  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. 时间格式转换成JUN.13,2017

    SimpleDateFormat sdf = new SimpleDateFormat("MMM.dd,yyyy", Locale.ENGLISH); String negotia ...

  2. 初识DataGridView 表格数据控件

    DataGridView控件提供了一种强大而灵活的以表格形式显示数据的方式,用户可以使用DataGridView控件来显示少量数据的只读视图,也可以对其进行缩放以显示特大数据集的可编辑视图. 扩展Da ...

  3. vscode 安装插件,和相关配置

    安装插件,配置对应的用户设置,进行替换,实现插件功能的生效 { // 控制是否在搜索中跟踪符号链接. "search.followSymlinks": false, "e ...

  4. Vue学习笔记:Slot

    转自:https://www.w3cplus.com/vue/vue-slot.html 在Vue中,slot也分多种,从Vue的官网中可以获知,其主要分为:单个插槽.具名插槽和作用域插槽三种 父组件 ...

  5. [javaSE] 多线程(售票例子)

    需求:简单的买票程序,多个窗口卖票,多线程 定义一个类Ticket实现Runnable接口, 定义成员属性int类型的票数nums 实现run()方法,run方法中 while(true)的死循环,打 ...

  6. 撩课-Python-每天5道面试题-第1天

    一. 尽可能详细的描述出一个应用软件, 比如QQ, 在计算机中运行时涉及的软硬件, 以及说明我们编程的侧重点? 电脑开机, 从硬盘中(外部存储设备)加载操作系统(系统软件)到内存(内部存储设备), 并 ...

  7. 【SSH网上商城项目实战04】EasyUI菜单的实现

    转自:https://blog.csdn.net/eson_15/article/details/51297705 上一节我们使用EasyUI搭建了后台页面的框架,这一节我们主要使用EasyUI技术简 ...

  8. pollard_rho 算法进行质因数分解

    //************************************************ //pollard_rho 算法进行质因数分解 //*********************** ...

  9. Zookeeper JAVA API的使用

    0. 前言 zookeeper安装及使用  http://www.cnblogs.com/rocky-fang/p/7880309.html 1. 开发环境配置 1.1 idea创建一个maven工程 ...

  10. UOJ46. 【清华集训2014】玄学

    传送门 Sol 考虑对于操作时间建立线段树,二进制分组 那么现在主要的问题就是怎么合并信息 你发现一个性质,就是每个修改只会在整个区间内增加两个端点 那么我们二进制分组可以得到每个区间内最多只有区间长 ...