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. PHP代码审计笔记--弱类型存在的安全问题

    0x01 前言 PHP 是一门弱类型语言,不必向 PHP 声明该变量的数据类型,PHP 会根据变量的值,自动把变量转换为正确的数据类型. 弱类型比较,是一个比较蛋疼的问题,如左侧为字符串,右侧为一个整 ...

  2. RF-获取上个月份

    验证1: case ${NowDate} set variable 20170103 ${year} set variable ${NowDate[0:4]} ${month} set variabl ...

  3. 【RF库XML测试】parse xml

    Name:Parse XmlSource:XML <test library>Arguments:[ source | keep_clark_notation=False ]Parses ...

  4. iOS开发-编译出错 duplicate symbols for architecture x86_64

    今天对原来项目文件进行重新整理,根据文件内容进行分类,结果复制粘贴时没注意把一个文件复制了两遍 编译的时候就出现Duplicate Symbol Error 在网上搜素了一圈发现也有人遇到过这个问题, ...

  5. 《征服C指针》读书笔记

    本文同时发布在我的个人博客上,欢迎访问~ www.seekingdream.cn 在读完K&R之后,对C的认识就是指针.数组.网上的人们对指针也有些“敬而远之”的感觉.最近从同学处淘得< ...

  6. python错误 ImportError: No module named setuptools 解决方法[转]

    在python运行过程中出现如下错误: python错误:ImportError: No module named setuptools这句错误提示的表面意思是:没有setuptools的模块,说明p ...

  7. 原生js--HTTP进度事件

    1.HTTP进度事件属于XHR2规范定义的系列事件 2.事件模型中会触发不同的事件,所以不再需要检查readyState事件 3.当调用send()时,触发loadstart事件 4.当正在加载服务器 ...

  8. 高性能Android应用开发

  9. Redis学习笔记--Redis配置文件Sentinel.conf参数配置详解

    redis-sentinel.conf配置项说明如下: 1.port 26379 sentinel监听端口,默认是26379,可以修改. 2.sentinel monitor <master-n ...

  10. LeetCode 79 Word Search(单词查找)

    题目链接:https://leetcode.com/problems/word-search/#/description 给出一个二维字符表,并给出一个String类型的单词,查找该单词是否出现在该二 ...