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. Linux环境下MySQL设置gbk编码

    1 编辑mysql配置文件 vi /etc/my.cnf 2 创建数据库 CREATE DATABASE `XXX` DEFAULT CHARACTER SET gbk COLLATE gbk_chi ...

  2. Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie

    Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie >>>>>>>>>>>>& ...

  3. java中调用groovy

    Groovy在Java中的应用,做几个小例子以备查 package com.boco.efficiency.groovy; import groovy.lang.Binding; import gro ...

  4. 第1章 Ansible 简介

    1. Ansible 优点 (1) 易读的语法:Ansible使用playbook作为配置管理脚本,playbook是基于YAML开发的,是一种易于读写的数据格式(2) 远程主机无须安装任何依赖:被A ...

  5. Unity透明Shader

    Shader "Custom/Blocks" { Properties { _Color (,,,) _MainTex ("Albedo (RGB)", 2D) ...

  6. Ansible的Playbook的编写

    在Ansible中,将各个模块组合起来成为一个YAML格式的配置文件,这个配置文件叫做Playbook, Playbook和模块的关系类似于shell脚本和Linux命令之间的关系. Playbook ...

  7. 深入浅出MFC——MFC程序的生死因果(三)

    1. 本章主要目的:从MFC程序代码中检验出一个Windows程序原本该有的程序进入点(WinMain).窗口类注册(RegisterClass).窗口产生(CreateWindow).消息循环(Me ...

  8. cp自动创建层级结构的例子

    一个拷贝命令的技巧,不仅拷贝文件,而且拷贝目录结构.记录下来. *拷贝的时候,自动创建参数中源文件的路径:#cp --parents parentdir1/parentdir2/sourcefile ...

  9. 《转载》Eclipse项目上传码云

    本文转载自http://blog.csdn.net/izzyliao/article/details/53074452 把Eclipse项目上传到码云的步骤: 1.登录码云:新建项目 2.输入项目名: ...

  10. Matlab练习——矩阵和数组的操作

    题目来自:<战胜MATLAB必做练习50道> 题目有更改,改成了我想写的样子. 1. 创建一个3×3矩阵,并将其扩充为4×5矩阵 clear; clc; mat1 = ones(,) ma ...