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 ...
随机推荐
- java/resteasy批量下载存储在阿里云OSS上的文件,并打包压缩
现在需要从oss上面批量下载文件并压缩打包,搜了很多相关博客,均是缺胳膊少腿,要么是和官网说法不一,要么就压缩包工具类不给出 官方API https://help.aliyun.com/documen ...
- 深入理解JavaScript系列(47):对象创建模式(上篇)
介绍 本篇主要是介绍创建对象方面的模式,利用各种技巧可以极大地避免了错误或者可以编写出非常精简的代码. 模式1:命名空间(namespace) 命名空间可以减少全局命名所需的数量,避免命名冲突或过度. ...
- wcf 基本配置
<system.serviceModel> <services> <service name="ServiceUpdater.ServiceUpdate&quo ...
- ASP.NET MVC4 新手入门教程之九 ---9.查询详情和删除方法
在本教程的这一部分,您会检查自动生成的Details和Delete方法. 检查详细信息和删除方法 打开Movie控制器并检查的Details的方法. public ActionResult Detai ...
- jquery+springMVC实现文件上传
此文章是基于 搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台 一. jar包介绍 1. commons-fileupload-1.3.1.jar 二. 相关程序 ...
- unity3d之相机跟随人物
一.第三人称视角 _1 先设置好相机与玩家之间的角度 给相机添加代码 using UnityEngine; using System.Collections; namespace CompletePr ...
- java计数
计数 package com.demo; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent ...
- mysql通过一张表更新另一张表
在mysql中,通过一张表的列修改另一张关联表中的内容: 1: 修改1列 update student s, city c set s.city_name = c.name where s.city ...
- cookie实现记住登录名和密码
在最近学习的session作用域中,顺便了解了一下cookie, session是存放在服务器中,而cookie是存放在客户端中. 本篇文章主要是使用cookie来实现记住密码的功能. 简单的logi ...
- 【Android】Android studio 编译问题:finished with non-zero exit value 2
1.Android studio 编译问题:finished with non-zero exit value 2 问题: Error:Execution failed for task ':andr ...