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 ...
 
随机推荐
- .NET加密技术概述
			
微软.NET 的System.Security.Cryptography中的类实现了各种具体的加密算法和技术.这些类,有一些是非托管 Microsoft CryptoAPI 的包装,而另一些则是纯粹的 ...
 - jmeter(5)——参数化
			
之前接触过QTP或者Loadrunner的小伙伴,应该对参数化不陌生,在<badboy详解篇>中也介绍了badboy的参数化,今天说一下jmeter的参数化,同样,我们举例说明,以msn. ...
 - [转载+补充][PY3]——环境配置(2)——windows下安装pycharm并连接Linux的python环境
			
原文地址:<你所会用到的Python学习环境和工具> 1. 下载安装Pycharm专业版 具体方法略.Pycharm5激活方法参考http://www.cnblogs.com/snsdzj ...
 - MongoDB 学习(二)可视化界面
			
一.安装可视化界面 1.mongobooster 安装和配置 1.下载安装 下载地址:https://nosqlbooster.com/downloads 下载完成后直接点击安装: 安装完成弹出界面: ...
 - Collatz 序列、逗号代码、字符图网格
			
1.collatz序列 编写一个名为 collatz()的函数,它有一个名为 number 的参数.如果参数是偶数, 那么 collatz()就打印出 number // 2,并返回该值.如果 num ...
 - 谈谈我从工作中理解的CDN
			
一.CDN定义 CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快.更稳定.通过 ...
 - JavaScript This -笔记
			
参考文章:blog.crimx.com/2016/05/12/understanding-this/ 在es6箭头函数之前this是执行时候确定的,而非定义时候确定.函数都是被调用的,调用时找前面调用 ...
 - AngularJS实现原理
			
个人觉得,要很好的理解AngularJS的运行机制,才能尽可能避免掉到坑里面去.在这篇文章中,我将根据网上的资料和自己的理解对AngularJS的在启动后,每一步都做了些什么,做一个比较清楚详细的解析 ...
 - springmvc封装list个数限制问题
			
提交一颗树,三级区域个数大于1000个导致提交失败!!! org.springframework.beans.InvalidPropertyException: Invalid property 'd ...
 - sprintf详解
			
原文:http://www.cnblogs.com/wqlblogger/archive/2007/01/09/615525.html 转摘声明:选自<CSDN 社区电子杂志——C/C++杂志& ...