Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃
Codeforces Round #435 (Div. 2)
codeforces 862 A. Mahmoud and Ehab and the MEX【水】
题意:定义一个集合的MEX为其中的最小的不在集合里的非负整数,现在给一个大小为N的集合和X,每次操作可以向其中加入一个非负整数或删除一个数,问最小的操作次数,使得这个集合的MEX为X。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[];
int main() {
int n, x, i, j, ans = , cnt = ;
scanf("%d %d", &n, &x);
for(i = ; i <= n; ++i) {
scanf("%d", &a[i]);
if(a[i] < x) cnt++;
else if(a[i] == x) ans++;
}
ans += x - cnt;
printf("%d\n", ans);
return ;
}
15ms
codeforces 862 B. Mahmoud and Ehab and the bipartiteness【dfs】
题意:给一棵n个结点的树,问最多能加多少边使得其是二分图并且不能有重边和自环。
题解:dfs染色算出可匹配最多数,将其减去n-1即为答案。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>g[];
int a[];
void dfs(int x, int fa, int t) {
a[t]++;
int len = g[x].size();
for(int i = ; i < len; ++i)
if(g[x][i] != fa) dfs(g[x][i], x, t^);
}
int main() {
int n, u, v, i;
scanf("%d", &n);
for(i = ; i <= n; ++i) g[i].clear();
a[] = a[] = ;
for(i = ; i<n-; ++i) {
scanf("%d%d", &u, &v);
g[u].push_back(v); g[v].push_back(u);
}
dfs(, , );
long long ans = 1ll*a[]*a[] - (n-);
printf("%lld\n", ans);
return ;
}
78ms
codeforces 862 C. Mahmoud and Ehab and the xor【构造】
题意:要构造n(≤10^5)个不同的非负整数(每个数≤10^6),使得它们异或和为x(≤10^5)。
题解:考察异或的自反性。注意观察数据范围,用特殊数据完成构造。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std; int main() {
int n, x, i;
scanf("%d%d", &n, &x);
if(n==) printf("YES\n%d\n", x);
else if(n == ) {if(!x) puts("NO");else printf("YES\n0 %d\n", x);}
else {
printf("YES\n");
for(i = ; i < n-; ++i) {printf("%d ", i); x ^= i;}
printf("%d %d %d\n", (<<), (<<), (<<)^(<<)^x);
}
return ;
}
31ms
待补。。= _ =
codeforces 862 D. Mahmoud and Ehab and the binary string【二分】
题意:已知一个01字符串的长度n (2 ≤ n ≤ 1000)(保证字符串至少包含一个0和一个1),现在你可以进行若干次询问(不超过15次),每次询问输出一个字符串,对应的输入给出了原字符串和你询问字符串的汉明距离(汉明距离:两个字符串对应位置的不同字符的个数),最后再输出原字符串任意一个0和一个1的位置。
题解:二分区间判断。利用两组询问的差值,看一个区间里有没有0或1。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int N = ;
char s[N], t[N];
int main() {
int n, i, d1, d2, l, r;
scanf("%d", &n);
for (i = ; i < n; i++) s[i] = '';
printf("? %s\n", s); fflush(stdout);
int p0 = , p1 = ;
l = , r = n - ;
scanf("%d", &d1);
while (l <= r) {
int m = (l + r) >> ;
strcpy(t, s);
for(i = l; i <= m; i++) t[i] = '';
printf("? %s\n", t); fflush(stdout);
scanf("%d", &d2);
if ((d2-d1) == (m-l+)) {
p0 = m; l = m + ; //printf("p0=%d\n",p0);
continue;
}
if ((d1-d2) == (m-l+)) {
p1 = m; l = m + ; //printf("p1=%d\n",p1);
continue;
}
r = m;
}
printf("! %d %d\n", p0+, p1+); fflush(stdout);
return ;
}
15ms
Codeforces Round #435 (Div. 2)【A、B、C、D】的更多相关文章
- 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 #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- 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 #435 (Div. 2) A B C D】
CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意: 输入n,x(n,x& ...
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...
随机推荐
- log4j 简单用法
maven添加必要库: <!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <gro ...
- Shiro - web应用
先不谈Spring,首先试着用最简易的方式将Shiro集成到web应用. 即使用一些Servlet ContextListener.Filter.ini这些简单的配置完成与web应用的集成. web. ...
- Redis实现主从复制(Master&Slave)
由于前段时间公司项目比较赶,一直抽不出时间写博客,今天偷空写一篇吧.前面给大家讲解了单机版redis的基本操作,现在继续给大家讲解一下Redis的进阶部分,主从复制和读写分离. 一.Master&am ...
- 八 SocketChannel
SocketChannel是一个连接到Tcp网络套接字的通道.可以通过以下两种方式创建SocketChannel: 1.打开一个SocketChannel并连接到互联网上的某台服务器. 2.一个新连接 ...
- Python中的一些特殊函数
阅读目录 1. 过滤函数filter 2. 映射和归并函数map/reduce 3. 装饰器@(有参数和无参数) 4. 匿名函数lamda 回到顶部 1. 过滤函数filter 定义:filter 函 ...
- 深入理解jQuery插件开发总结(四)
jQuery插件开发模式 软件开发过程中是需要一定的设计模式来指导开发的,有了模式,我们就能更好地组织我们的代码,并且从这些前人总结出来的模式中学到很多好的实践. 根据<jQuery高级编程&g ...
- 前端学习之路之CSS (二)
Infi-chu: http://www.cnblogs.com/Infi-chu/ id选择器id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式,CSS 中 id 选择器以 &quo ...
- JavaScript String对象常用方法
length 返回字符串的长度(字符数) var str='Hello World!'; str.length; charAt() 返回指定位置的字符,第一个字符位置为0 var str='Hello ...
- vue双向绑定笔记
原文:https://github.com/louzhedong/blog/issues/4 <!DOCTYPE html> <html lang="en"> ...
- mongoDB (mongoose、增删改查、聚合、索引、连接、备份与恢复、监控等等)
MongoDB - 简介 官网:https://www.mongodb.com/ MongoDB 是一个基于分布式文件存储的数据库,由 C++ 语言编写,旨在为 WEB 应用提供可扩展的高性能数据存储 ...