A. Mahmoud and Ehab and the MEX

题目链接:http://codeforces.com/contest/862/problem/A

题目意思:现在一个数列中有n个数,每个数小于等于100,现在要让这个数列的met=k,意思是如果从1-100中第一个未出现的数字为met。

题目思路:在[0,k)区间内所有在数列中不存在的数的数量+check(k),check()表示判断k是否存在,如果存在返回1,不存在返回0;

代码:

 //Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
const long long mod=1e9+;
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define endl "\n"
II a[]={};
int main() {
ios::sync_with_stdio(false);cin.tie();
II n,x;
cin>>n>>x;
for(II i=;i<n;i++){
II t;
cin>>t;
a[t]++;
}
II ans=;
for(II i=;i<x;i++){
if(a[i]==) ans++;
}
if(a[x]) ans++;
cout<<ans<<endl;
return ;
}

B. Mahmoud and Ehab and the bipartiteness

题目链接:http://codeforces.com/contest/862/problem/B

题目意思: 给定一个n 个节点  n-1 条边的图,求最多还能加几条边,保证 这个图不存在重边,自环,并且是一个二分图

题目思路:首先一个树是一个二分图,我们可以通过dfs可以把一个树的节点push进两个vector中,这样就构造了一个二分图,那么答案就是size1×size2-n+1.

代码:

 //Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
const long long mod=1e9+;
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define endl "\n"
II n;
vector<int>G[+];
vector<int>a[];
void dfs(II u,II fa,II s){
a[s].push_back(u);
for(II i=;i<G[u].size();i++){
II v=G[u][i];
if(v==fa) continue;
dfs(v,u,s^);
}
}
int main() {
ios::sync_with_stdio(false);cin.tie();
cin>>n;
if(n==){cout<<<<endl;return ;}
for(II i=;i<n-;i++){
II x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(,,);
LL sz1=a[].size();
LL sz2=a[].size();
cout<<sz1*sz2-n+<<endl;
return ;
}

Codeforces Round #435 (Div. 2)的更多相关文章

  1. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  2. 【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& ...

  3. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  4. E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound #include &l ...

  5. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  6. 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

    题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...

  7. Codeforces Round #435 (Div. 2) c+d

    C:给n和k要求,找出n个不同的数,使得亦或起来等于k 可以先预处理从1到1e5,找亦或起来等于(11111111111111111)(二进制)的所有对数,然后四个一起亦或就是0了,再和k亦或 可以看 ...

  8. Codeforces Round #435 (Div. 2) B (二分图) C(构造)

    B. Mahmoud and Ehab and the bipartiteness time limit per test 2 seconds memory limit per test 256 me ...

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

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

随机推荐

  1. SpringMVC由浅入深day01_1springmvc框架介绍

    springmvc 第一天 springmvc的基础知识 课程安排: 第一天:springmvc的基础知识 什么是springmvc? springmvc框架原理(掌握) 前端控制器.处理器映射器.处 ...

  2. http 返回码 405 解决方案之一

    今天做网络请求数据的时候遇到返回码405,当时就傻了~~ 故事是这样的-- 我用post请求访问一个url,服务端数据是一个json的txt文件,理论上直接访问,返回json,然后解析就没事了,可是今 ...

  3. vuejs时间格式化

    date.js export function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, ...

  4. vuejs监听苹果iphone手机键盘事件

    在iphone手机中,vue提供的keyup事件是不能监听iphone键盘的,但是h5提供的input事件可以做到. 只需要向下面这样处理,就可以解决iphone不响应键盘事件的bug <tem ...

  5. python中安装dlib和cv2

    这两个模块是很容易出问题的模块,以下的解决办法都是从网上收集而来. 安装dlib: pypi.python.org/pypi/dlib/19.6.0 下载 dlib-19.6.0-cp36-cp36m ...

  6. Kubernetes 集群:规划与搭建

    Kubernetes 集群环境: IP地址 主机名 角色 软硬件限制 192.168.119.134 master1 deploy ,master1 ,lb1 ,etcd (1) CPU至少1核,内存 ...

  7. [Ubuntu] arp-scan - 扫描网络设备

    使用arp-scan扫描所有网络设备信息. 1. 安装arp-scan ifantastic@ubuntu:~$ sudo apt-get install arp-scan 2. 扫描网络所有设备 i ...

  8. Java网络编程之TCP通信

    一.概述 Socket类是Java执行客户端TCP操作的基础类,这个类本身使用代码通过主机操作系统的本地TCP栈进行通信.Socket类的方法会建立和销毁连接,设置各种Socket选项. Server ...

  9. 服务器搭建--Linux安装erlang

    1.安装依赖环境: 1)安装GCC GCC-C++ Openssl等模块,安装过就不需要安装了 yum -y install make gcc gcc-c++ kernel-devel m4 ncur ...

  10. 【Nginx系列】Nginx之location

    语法: location [=|~|~*|^~] patt { } 一.分类 中括号可以不写任何参数,此时称为一般匹配 也可以写参数 因此,大类型可以分为3种 location = patt {} [ ...