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. 自定义Hive函数

    7. 函数 7.1 系统内置函数 查看系统自带的函数:show functions; 显示自带的函数的用法:desc function upper(函数名); 详细显示自带的函数的用法:desc fu ...

  2. Dining(POJ-3281)【最大流】

    题目链接:https://vjudge.net/problem/POJ-3281 题意:厨师做了F种菜各一份,D种饮料各一份,另有N头奶牛,每只奶牛只吃特定的菜和饮料,问该厨师最多能满足多少头奶牛? ...

  3. Robot 安装

    安装一个测试环境的 下载python27 升级pip E:\Python27\python -m pip install --upgrade pip 安装robotramework E:\Python ...

  4. Http 与 Https区别

    传统Http协议弊端 传统Http协议弊端是明文的,如果别人采用抓包分析可以获取到明文数据. 什么是Https协议 HTTPS(Hyper Text Transfer Protocol over Se ...

  5. 解决 Linux grep 不高亮显示

    今天偶然发现一个问题,在 grep 日志的过程中,搜出来一大坨但是被 grep 的那一段未高亮显示,属实有些难受,高亮显示是 Linux 的高亮本来就是 Linux 的功能,与连接工具(我用的 xsh ...

  6. axios全局配置及拦截器

    axios使用说明文档 axios 全局配置: //axios-init.js import axios from 'axios': let loadingInstance; //创建Loading ...

  7. 听课笔记--DP--最大子矩阵和

    最大子矩阵问题 给定一个n*n(0<n<=120)的矩阵, 矩阵内元素有正有负, 请找到此矩阵的内部元素和最大的子矩阵 样例输入: 4 0 -2 -7  0  9  2 -6  2  -4 ...

  8. S2-019、S2-020

    前言 “Struts2系列起始篇”是我整各系列的核心,希望大家能花些时间先看看. 正文 我发现关于一些早期的Struts2的漏洞,网上的分析文章并不多,不知道是不是我打开浏览器的方式不对,唯一看到的两 ...

  9. win8怎么强制删除文件

    转自:https://www.jizhuba.com/zhichanglicai/20180119/5705.html 方法/步骤1.例如我们想删除桌面上的“123”文件夹,发现无法删除.2.可以这样 ...

  10. python matplotlib以日期为x轴作图

    from datetime import datetime, date, timedelta import matplotlib.pyplot as plt import tushare as ts ...