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. Redis 【string】 一句话说明

    APPEND----------------------------------------------在字符串后面追加 BITCOUNT------------------------------- ...

  2. Swift函数_外部参数名,

    //1________________ /** *没使用外部参数名的函数 */ func inputScore(name:String,score1:Int,score2:Int) { } /** * ...

  3. zabbix使用(自定义监控、自动报警)

    自定义监控(制作模板) zabbix自带模板Template OS Linux (Template App Zabbix Agent)提供CPU.内存.磁盘.网卡等常规监控,只要新加主机关联此模板,就 ...

  4. [javaSE] 多线程(守护线程)

    我们一般使用多线程,都是while的死循环,想要结束线程,只需退出死循环即可 当线程中调用了sleep()方法或者wait()方法,当前的线程就会进入冻结状态,这个线程就结束不了 调用Thread对象 ...

  5. http_proxy_module 模块(proxy_pass 指令)

    1. proxy_pass 指令介绍 该指令属于 http_proxy_module, http_proxy_module 模块可以将请求转发到另一台服务器. 在 nginx 反向代理是,会通过 lo ...

  6. win下gosublime配置ctag

    ctags(Generate tag files for source code)是vim下方便代码阅读的工具.尽管ctags也可以支持其它编辑器,但是它正式支持的只有VIM.并且VIM中已经默认安装 ...

  7. Redis概述与安装

    一.什么是Redis ​ 由c语言编写的,以键值对的形式存储的数据库. 缓存技术(驻留在内存中) ​ key:value ​ 支持5种数据类型: ​ String ​ Hash(哈希表) ​ list ...

  8. 解决react不能往setState中传key作为参数的办法(文章最后实现了传递key做参数的办法)

    读者朋友可以直接看最后一个分割线下面的那部分!利用方括号语法来动态的访问对象的属性,实现当参数为属性名的传递; 有时候我们需要每次单独设置众多state中的一个,但是,都是进行相同的操作,这时候如果每 ...

  9. 理解js中bind方法的使用

    提到bind方法,估计大家还会想到call方法.apply方法:它们都是Function对象内建的方法,它们的第一个参数都是用来更改调用方法中this的指向.需要注意的是bind 是返回新的函数,以便 ...

  10. JS 计算时间差,(引入外部字体文件)

    JavaScript Date() 对象: new Date() :时间对象,会把当前时间作为其初始值: setFullYear() :用于设置月份,可有三个参数,setFullYear(year,m ...