当前位置: 首页 > news >正文

Codeforces Round #435 (Div. 2)

最近我超级菜,菜到无法想象了
A. Mahmoud and Ehab and the MEX
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?

Input

The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.

The second line contains n distinct non-negative integers not exceeding 100 that represent the set.

Output

The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examples
input
5 3
0 4 5 6 7
output
2
input
1 0
0
output
1
input
5 0
1 2 3 4 5
output
0
Note

For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.

In the third test case the set is already evil.

 

 构造一个数组,使0到x-1都出现,x不能出现,所以找到这个值就好啦

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int n,x;
    cin>>n>>x;
    int a[105];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int pos=lower_bound(a,a+n,x)-a;
    if(a[pos]==x)pos--;
    pos=x-pos;
    cout<<pos<<endl;
    return 0;
}
A. Mahmoud and Ehab and the MEX
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?

Input

The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.

The second line contains n distinct non-negative integers not exceeding 100 that represent the set.

Output

The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examples
input
5 3
0 4 5 6 7
output
2
input
1 0
0
output
1
input
5 0
1 2 3 4 5
output
0
Note

For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.

In the third test case the set is already evil.

 

 二分图拥有的最大边数,就是左边点的个数*右边点的个数,还能增加的再减去当前的,我想的直接分组,这样是不对的,因为我会贪心选择他是左边还是右边,这个明显就是错的,所以dfs一下就好的

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+5;
vector<int>a[N];
int num[2],vis[N];
void dfs(int x,int f){
    for(auto X:a[x]){
        if(vis[X])continue;
        num[(f+1)%2]++;
        vis[X]=1;
        dfs(X,f+1);
    }
}
int main()
{
    int n;
    cin>>n;
    int s1=0,s2=0;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);

    }
    vis[1]=1;
    num[1]=1;
    dfs(1,1);
    cout<<1LL*num[0]*num[1]-n+1<<endl;
    return 0;
}
C. Mahmoud and Ehab and the xor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.

Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.

Input

The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively.

Output

If there is no such set, print "NO" (without quotes).

Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.

Examples
input
5 5
output
YES
1 2 4 5 7
input
3 6
output
YES
1 2 5
Note

You can read more about the bitwise-xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR

For the first sample .

For the second sample .

 

 异或嘛,不同得1

但这是一个构造啊,我想不出来

但是要找No 这个数据还是简单的,大概都能找到就是2个数怎么都凑不出0,因为2个相同的数异或为0

所以主要处理的的是n>2得,2^17次方超过1e5了,就利用这个特性构造另两个值就行

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    if(n==1)cout<<"YES\n"<<x;
    else if(n==2)
    {
        if(!x)cout<<"NO";
        else
        cout<<"YES\n"<<0<<" "<<x;
    }
    else
    {
        cout<<"YES\n";
        int y=0;
        for(int i=1;i<n-2;i++)
            y^=i,cout<<i<<" ";
        int a=1<<17,b=1<<18;
        cout<<a<<" "<<b<<" "<<(a^b^x^y);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7565210.html

相关文章:

  • 机器学习概述
  • 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
  • 从重复到重用
  • TPYBoard读取芯片上的温度传感器
  • 变量的保存重载和打印
  • Oracle将Java EE移交Eclipse基金会
  • Linux - 执行命令与脚本
  • HashMap ConcurrentHashMap
  • 第三百九十三节,Django+Xadmin打造上线标准的在线教育平台—Xadmin后台进阶开发配置...
  • 软件下载
  • 7. Oracle数据加载和卸载
  • 工作的第6个年头发现DateFormat是not synchronized
  • JAVA自学笔记18
  • android 9 patch
  • C#中string.format用法详解
  • 5、React组件事件详解
  • es6要点
  • HashMap剖析之内部结构
  • Java多线程(4):使用线程池执行定时任务
  • jQuery(一)
  • leetcode98. Validate Binary Search Tree
  • PHP面试之三:MySQL数据库
  • Python学习之路13-记分
  • rabbitmq延迟消息示例
  • vue2.0开发聊天程序(四) 完整体验一次Vue开发(下)
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • weex踩坑之旅第一弹 ~ 搭建具有入口文件的weex脚手架
  • 包装类对象
  • 记一次用 NodeJs 实现模拟登录的思路
  • 每天一个设计模式之命令模式
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 深入体验bash on windows,在windows上搭建原生的linux开发环境,酷!
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • Java数据解析之JSON
  • PostgreSQL 快速给指定表每个字段创建索引 - 1
  • 阿里云API、SDK和CLI应用实践方案
  • 阿里云移动端播放器高级功能介绍
  • 好程序员大数据教程Hadoop全分布安装(非HA)
  • 整理一些计算机基础知识!
  • ​力扣解法汇总946-验证栈序列
  • !!java web学习笔记(一到五)
  • (八)Docker网络跨主机通讯vxlan和vlan
  • (第二周)效能测试
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • (七)Java对象在Hibernate持久化层的状态
  • (五)IO流之ByteArrayInput/OutputStream
  • (一)为什么要选择C++
  • (译)计算距离、方位和更多经纬度之间的点
  • .aanva
  • .NET CF命令行调试器MDbg入门(三) 进程控制
  • .NET 中什么样的类是可使用 await 异步等待的?
  • @ConfigurationProperties注解对数据的自动封装
  • [ vulhub漏洞复现篇 ] AppWeb认证绕过漏洞(CVE-2018-8715)
  • [<事务专题>]