Codeforces Round #435 (Div. 2)
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)的更多相关文章
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- 【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& ...
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound #include &l ...
- 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- 【构造】【分类讨论】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, ...
- Codeforces Round #435 (Div. 2) c+d
C:给n和k要求,找出n个不同的数,使得亦或起来等于k 可以先预处理从1到1e5,找亦或起来等于(11111111111111111)(二进制)的所有对数,然后四个一起亦或就是0了,再和k亦或 可以看 ...
- 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 ...
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...
随机推荐
- Java md5加密 控制台传入与web传入参数 结果不匹配 || 相同字符串加密结果不同,如何保证JAVA MD5加密结果在不同的环境下都相同
开发中遇到md5加密不一致问题,排除了上下文编码,加密内容问题. 爬了各类资料,最终找到了原因. /** 对字符串进行MD5加密 */ private static String encodeByMD ...
- flexbox父盒子flex-direction属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 利用函数来得到所有子节点号& 利用函数来取得最高级的节点号
在Oracle 中我们知道有一个 Hierarchical Queries 通过CONNECT BY 我们可以方便的查了所有当前节点下的所有子节点.但很遗憾,在MySQL的目前版本中还没有对应的功能. ...
- 个人成长|荣获CNVD年度最有价值漏洞奖
本文共750+字,预计阅读2-3分钟. 前几天,很荣幸受主办方邀请,还拿了CNVD的一个“年度最有价值漏洞奖”,说一说,这几天的故事吧. 11月20号,意外收到一个会议邀请,当时还比较诧异,印象中我在 ...
- asp.net 验证码
Before proceeding with the topic first we must understand "What is a Captcha code?" and &q ...
- PHP中常见问题总结
[1]页面之间无法传递变量 get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_ ...
- 【架构师之路】 LVS+Keepalived实现高可用负载均衡
一.原理 1.概要介绍 如果将TCP/IP划分为5层,则Keepalived就是一个类似于3~5层交换机制的软件,具有3~5层交换功能,其主要作用是检测web服务器的状态, ...
- Python 编码规范(Google)
Python 编码规范(Google) https://blog.csdn.net/q469587851/article/details/54096093 Python 风格规范(Google) 本项 ...
- 日记整理---->2017-05-17
起始时间是2017-05-17,记录一下spring的学习过程.陌生人可以变成熟人,但熟人一旦变成陌生人,就再也回不去了. 一.测试一下init-method和depend-on huhx.xml文件 ...
- JS案例 - 基于vue的移动端长按手势
================================惯例碎碎念前言================================ 当时首先想到要做长按事件的时候,我想到的是vue内部的自 ...