2019牛客暑期多校训练营(第五场)F maximum clique 1 二分图求最大独立集
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 二分图求最大独立集的更多相关文章
- 2019牛客暑期多校训练营(第三场)- F Planting Trees
题目链接:https://ac.nowcoder.com/acm/contest/883/F 题意:给定n×n的矩阵,求最大子矩阵使得子矩阵中最大值和最小值的差值<=M. 思路:先看数据大小,注 ...
- 2019牛客暑期多校训练营(第五场) maximum clique 1
题意:给出n个不相同的数,问选出尽量多的数且任两个数字二进制下不同位数大于等于2. 解法:能想到大于等于2反向思考的话,不难发现这是一个二分图,那么根据原图的最大团等于补图的最大独立点集,此问题就变成 ...
- 2019牛客暑期多校训练营(第三场) F.Planting Trees(单调队列)
题意:给你一个n*n的高度矩阵 要你找到里面最大的矩阵且最大的高度差不能超过m 思路:我们首先枚举上下右边界,然后我们可以用单调队列维护一个最左的边界 然后计算最大值 时间复杂度为O(n*n*n) # ...
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...
- 2019牛客暑期多校训练营(第一场) B Integration (数学)
链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...
- 2019牛客暑期多校训练营(第二场)F.Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...
- 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...
- [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem
链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
随机推荐
- FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated;
/Users/jerryqi/PycharmProjects/DeepLearning/venv/lib/python3.7/site-packages/tensorflow/python/frame ...
- Jmeter做HTTP接口测试
接口测试概述:https://www.cnblogs.com/mawenqiangios/p/7886115.html Jmeter接口测试教程:https://www.cnblogs.com/hou ...
- laravel中间件的实现原理
中间件的实现原理 运用 array_reduce 以及 call_user_func 实现 interface Middleware { public static function handle(C ...
- wordpress 后台无法登录 网站内容缺失
昨天网站又突然不正常了,前两天都是好的.. 具体来说就是wp后台登录不进去,一直在登录页跳转,与此同时服务器上其他网站也有这个问题,而且有些网站的板块内容也缺失了, 所以首要就是要登录进后台看看是不是 ...
- 探索grafana
因为zabbix的监控图形不够美观,功能也不够强大, 那么就用到了grafana 填写zabbix插件配置: 如下需要根据主机群组和主机名来完成图形: grafana报警如下: 解决如下: 更改标准设 ...
- 1234: 约瑟夫问题-输出最后的编号(Java)
WUSTOJ 1234: 约瑟夫问题-输出最后的编号 参考资料 约瑟夫问题--百度百科 Description n个人围成一圈,依次从1至n编号.从编号为1的人开始1至k报数,凡报数为k的人退出圈子, ...
- vue-cookies的使用
安装vue-cookies npm install vue-cookies --save 使用vue-cookies // 在main.js中 // require var Vue = require ...
- SpringBoot exception异常处理机制源码解析
一.Spring Boot默认的异常处理机制 1:浏览器默认返回效果 2:原理解析 为了便于源码跟踪解析,在·Controller中手动设置异常. @RequestMapping(value=&quo ...
- java 字符串处理的
@Test public void testString(){ /*字符串处理 */ String email="123456789@qq.com"; System.out.pri ...
- ASM实例远程连接
存在一个软件,远程连接ASM实例 tj2:/picclife/app/grid$ lsnrctl status Listening Endpoints Summary... (DESCRIPTION= ...