//在我对着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】的更多相关文章

  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 #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  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 #435 (Div. 2) A B C D】

    CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意:      输入n,x(n,x& ...

  9. 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...

随机推荐

  1. Android OpenGL教程-第四课【转】

    第四课 旋转: 在这一课里,我将教会你如何旋转三角形和四边形.左图中的三角形沿Y轴旋转,四边形沿着X轴旋转. 我们增加两个变量来控制这两个对象的旋转.这两个变量加在程序的开始处其他变量的后面.它们是浮 ...

  2. angularjs之UI Grid 的刷新 本地数据源及HTTP数据源

    关键代码: 如果数据源是本地数据$("#hidJsonData").val("[]");   var myJsonData = [];   if ($(&quo ...

  3. java 并发(五)---AbstractQueuedSynchronizer(5)

    问题 : ArrayBlockQueue 和 LinkedBlockQueue 的区别 两者的实现又是怎么样的 应用场景 BlockingQueue 概述 blockingQueue 是个接口,从名字 ...

  4. ul li各属性设置

    1. ul li删除前面的黑点:style=“list-style:none;” <ul style=“list-style:none;”> <li></li> & ...

  5. css3打包后自动追加前缀插件:autoprefixer

    用vue-cli构建的项目脚手架已经帮你把autoprefixer的配置做好了,自己不需要做什么改动就会自动加前缀: 下面一起看看涉及到autoprefixer这个插件的一些配置: 1,postcss ...

  6. KNN 与 K - Means 算法比较

    KNN K-Means 1.分类算法 聚类算法 2.监督学习 非监督学习 3.数据类型:喂给它的数据集是带label的数据,已经是完全正确的数据 喂给它的数据集是无label的数据,是杂乱无章的,经过 ...

  7. 创建第一个windows服务

    windows服务应用程序是一种长期运行在操作系统后台的程序,它对于服务器环境特别适合,它没有用户界面,不会产生任何可视输出,任何用户输出都回被写进windows事件日志. 计算机启动时,服务会自动开 ...

  8. AdvStringGrid入门使用

    仅仅把数据从数据库中显示到AdvStringGrid中 procedure TForm1.btnQueryClick(Sender: TObject); var i, j: Integer; begi ...

  9. idea output 消失找不到

    今天一不小心把idea的 debug的控制台output 搞丢了, 半天找不到,原来是在这里隐藏着 Restore layout

  10. Spring boot配置注意事项

    SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! “Application类”是指SpringBoot项目入口类.这个类的位置很关键: 如果App ...