https://ac.nowcoder.com/acm/contest/885/F

#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define fio ios::sync_with_stdio(false);cin.tie(0);
#define lowbit(x) (x&(-x))
#define db double
#define N 5010
const double Pi=3.14159265;
//const int N=2e6+10;
const ull base=;
const int INF=0x3f3f3f3f;
const int mod=1e9+;
const db eps=1e-;
const db pi=acos(-);
using namespace std;
int a[];
int n;
int cy[N],cx[N];
bool ev[N],f[N],mt[N];
struct node{
int to,nxt;
}g[N*];
int head[N],cnt;
void add(int u,int v){
g[cnt].to=v;
g[cnt].nxt=head[u];
head[u]=cnt++;
}
bool check(int x,int y){
int k=;
while(x||y){
if((x&)!=(y&)){
k++;
}
x>>=;
y>>=;
}
return k<=;
}
bool dfs(int u){
for(int i=head[u];i!=-;i=g[i].nxt){
if(!f[g[i].to]){
f[g[i].to]=;
if(!cy[g[i].to]||dfs(cy[g[i].to])){
cx[u]=g[i].to;
cy[g[i].to]=u;
return ;
}
}
}
return ;
}
void dfs2(int u){
mt[u]=;
for(int i=head[u];i!=-;i=g[i].nxt){
if(!f[g[i].to]){
f[g[i].to]=;
if(cx[g[i].to]&&cx[g[i].to]!=u){
mt[g[i].to]=;
dfs2(cx[g[i].to]);
}
}
}
return ;
}
int ans[N];
int main(){
memset(head,-,sizeof(head));
scanf("%d",&n);
int k,x;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
x=a[i];
k=;
while(x){
if(x&){
k++;
}
x>>=;
}
if(k&){
ev[i]=;
}
for(int j=;j<i;j++){
if(check(a[i],a[j])){
add(i,j);
add(j,i);
}
}
}
for(int i=;i<=n;i++){
if(ev[i]){
memset(f,,sizeof(f));
dfs(i);
}
}
for(int i=;i<=n;i++){
if(!ev[i]&&!cy[i]){
memset(f,,sizeof(f));
dfs2(i);
}
}
int tot=;
for(int i=;i<=n;i++){
if(ev[i]!=mt[i]){
ans[++tot]=a[i];
}
}
printf("%d\n",tot);
for(int i=;i<tot;i++){
printf("%d ",ans[i]);
}
printf("%d\n",ans[tot]);
return ;
}

2019牛客暑期多校训练营(第五场)F maximum clique 1 二分图求最大独立集的更多相关文章

  1. 2019牛客暑期多校训练营(第三场)- F Planting Trees

    题目链接:https://ac.nowcoder.com/acm/contest/883/F 题意:给定n×n的矩阵,求最大子矩阵使得子矩阵中最大值和最小值的差值<=M. 思路:先看数据大小,注 ...

  2. 2019牛客暑期多校训练营(第五场) maximum clique 1

    题意:给出n个不相同的数,问选出尽量多的数且任两个数字二进制下不同位数大于等于2. 解法:能想到大于等于2反向思考的话,不难发现这是一个二分图,那么根据原图的最大团等于补图的最大独立点集,此问题就变成 ...

  3. 2019牛客暑期多校训练营(第三场) F.Planting Trees(单调队列)

    题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) # ...

  4. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  5. 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...

  6. 2019牛客暑期多校训练营(第一场) B Integration (数学)

    链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...

  7. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  8. 2019牛客暑期多校训练营(第二场)F.Partition problem

    链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...

  9. 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...

  10. [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem

    链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

随机推荐

  1. 转:SLAM算法解析:抓住视觉SLAM难点,了解技术发展大趋势

    SLAM(Simultaneous Localization and Mapping)是业界公认视觉领域空间定位技术的前沿方向,中文译名为“同步定位与地图构建”,它主要用于解决机器人在未知环境运动时的 ...

  2. [转帖]PG语法解剖--基本sql语句用法入门

    PG语法解剖--基本sql语句用法入门 https://www.toutiao.com/i6710897833953722894/ COPY 命令挺好的 需要学习一下. 原创 波波说运维 2019-0 ...

  3. 串口(USART)通信-串口通讯协议简介

    物理层:规定通讯系统中具有机械.电子功能部分的特性,确保原始数据在物理媒体的传输.其实就是硬件部分. 协议层:协议层主要规定通讯逻辑,统一收发双方的数据打包.解包标准.其实就是软件部分. 简单来说物理 ...

  4. C++ 中不能声明为虚函数的函数有哪些?

    目录 普通函数 构造函数 内联成员函数 静态成员函数 友元函数 普通函数 普通函数(非成员函数)只能被overload,不能被override,而且编译器会在编译时绑定函数. 多态的运行期行为体现在虚 ...

  5. flask返回自定义的Response

    from json import dumps from flask import Response from flask_api import status from protocol.errors_ ...

  6. [Office 365] Office 365与Visio 2013/2016兼容性测试

                  Visio Professional 2013 (x64) - (Chinese-Simplified) 详细信息 文件名 cn_visio_professional_20 ...

  7. VS2013+WDK8.1 驱动开发环境配置

    Windows Driver Kit 是一种完全集成的驱动程序开发工具包,它包含 WinDDK 用于测试 Windows 驱动器的可靠性和稳定性,本次实验使用的是 WDK8.1 驱动开发工具包,该工具 ...

  8. py kafka

    # https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/consumer.py #生产者 impor ...

  9. [异步请求]ajax、axios、fetch之间的详细区别以及优缺点

    1.jQuery ajax  $.ajax({ type: 'POST', url: url, data: data, dataType: dataType, success: function () ...

  10. (一)Centos之VMware虚拟机安装

    一.下载 64位的VM12 安装包: http://pan.baidu.com/s/1bpzoXQZ 二.安装 点击下一步: 老规矩,打勾,下一步: 这里我们新建一个文件夹 VM12 最好放在D盘或者 ...