POJ1419 Graph Coloring
嘟嘟嘟
求无向图的最大独立集。
有这么一回事:最大独立集=补图的最大团。
所谓的最大团,就是一个子图,满足图中任意两点都有边。
然后ssy巨佬告诉了我一个很没有道理强的做法:随机。
每一次random_shuffle储存节点的数组,然后从头开始扫每一个点,能加入最大团就加入,否则continue。
最后看看是不是比当前答案优。
一直随机,直到一秒。
我也不知道这有什么道理,但就是过了。
.p.s:poj太慢了,得随机到0.3秒(竟然还能过)。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 105;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, m, G[maxn][maxn], pos[maxn];
int ans[maxn], Ans = 0;
int a[maxn], cnt = 0;
In bool check(int now)
{
for(int i = 1; i <= cnt; ++i) if(G[a[i]][now] == -1) return 0;
return 1;
}
In int solve()
{
cnt = 0;
for(int i = 1; i <= n; ++i) if(check(pos[i])) a[++cnt] = pos[i];
return cnt;
}
int main()
{
int T = read();
const db lim = 0.3 * CLOCKS_PER_SEC / T;
while(T--)
{
Mem(G, 0);
n = read(); m = read();
for(int i = 1; i <= m; ++i)
{
int x = read(), y = read();
G[x][y] = G[y][x] = -1;
}
Ans = 0;
for(int i = 1; i <= n; ++i) pos[i] = i;
Ans = 0;
db beg = clock(), end = beg;
while(end - beg < lim)
{
random_shuffle(pos + 1, pos + n + 1);
int tp = solve();
if(tp > Ans)
{
Ans = tp;
for(int i = 1; i <= Ans; ++i) ans[i] = a[i];
if(Ans == n) break;
}
end = clock();
}
write(Ans), enter;
sort(ans + 1, ans + Ans + 1);
for(int i = 1; i <= Ans; ++i) write(ans[i]), i == n ? enter : space;
}
return 0;
}
POJ1419 Graph Coloring的更多相关文章
- POJ1419 Graph Coloring(最大独立集)(最大团)
Graph Coloring Time Limit: 1000MS Memor ...
- poj1419 Graph Coloring 最大独立集(最大团)
最大独立集: 顶点集V中取 K个顶点,其两两间无连接. 最大团: 顶点集V中取 K个顶点,其两两间有边连接. 最大独立集=补图的最大团最大团=补图的最大独立集 #include<iostream ...
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4893 Accepted: 2271 ...
- uva193 - Graph Coloring
Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...
- UVA Graph Coloring
主题如以下: Graph Coloring You are to write a program that tries to find an optimal coloring for agiven ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
- poj 1419 Graph Coloring
http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- GPS-Graph Processing System Graph Coloring算法分析 (三)
HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158 Graph coloring is the problem of assignin ...
随机推荐
- Mongodb 集群实战
该实战过程完全跟着官网一步一步实现 ,官网教程:https://docs.mongodb.com/manual/tutorial/atlas-free-tier-setup/ 使用Mongo Shel ...
- Java学习笔记之——常用转义符号
\ 单独用会报错 \\ 打印右斜杠 \n 换行 \t Tab键 \" 双引号 \' 单引号
- 【Spring】25、Spring代理。 BeanNameAutoProxyCreator 与 ProxyFactoryBean
一般我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置文件的 ...
- jquery之行自加自减
实现目标:点击按钮复制本行,修改后重新插入到本行后面,点击复制出的行可删除本行 代码如下: <!DOCTYPE html> <html lang="en"> ...
- python爬虫入门---第四篇:网站对爬虫的限制及突破测试
大部分网站对网络爬虫都有限制,限制方式有两种: 一.Robots协议:二.网站通过判断对网站访问http的头部信息来查看是否是爬虫,并对爬虫做相关拦截 第一种限制是书面限制,第二种是强制性阻拦限制.那 ...
- jQuery之$.ajax()方法详解及实例
1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...
- IDEA项目搭建十——使用slf4j和logback进行日志记录
.简介 java里面日志分为两部分一个门面.一个实现,我们所熟知的SLF4j.Log4j.Log4j2.Logback的日志组件slf4j是门面提供的统一的入口,具体实现由log4j.log4j2.l ...
- 基于bootstrap的双日历插件 daterangepicker
我遇到需求是要求我将daterangepicker的一个双日期选择格式修改成两个单日期格式的日期选择框(方便手机端显示),要求如下: 1.两个单日期格式分别为开始日期和结束日期 2.开始日期可选择范围 ...
- list中放map的几种方式
package Test; import java.util.*; public class Test { public static void main(String[] args) { //第一种 ...
- (网页)20个JS 小技巧超级实用
转自CSDN: 1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false”< table border oncontextmenu=r ...