嘟嘟嘟




求无向图的最大独立集。

有这么一回事:最大独立集=补图的最大团。

所谓的最大团,就是一个子图,满足图中任意两点都有边。

然后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的更多相关文章

  1. POJ1419 Graph Coloring(最大独立集)(最大团)

                                                               Graph Coloring Time Limit: 1000MS   Memor ...

  2. poj1419 Graph Coloring 最大独立集(最大团)

    最大独立集: 顶点集V中取 K个顶点,其两两间无连接. 最大团: 顶点集V中取 K个顶点,其两两间有边连接. 最大独立集=补图的最大团最大团=补图的最大独立集 #include<iostream ...

  3. POJ 1419 Graph Coloring(最大独立集/补图的最大团)

    Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4893   Accepted: 2271   ...

  4. uva193 - Graph Coloring

    Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...

  5. UVA Graph Coloring

    主题如以下: Graph Coloring  You are to write a program that tries to find an optimal coloring for agiven ...

  6. Graph Coloring I(染色)

    Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...

  7. poj 1419 Graph Coloring

    http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...

  8. 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】

    Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5775   Accepted: 2678   ...

  9. GPS-Graph Processing System Graph Coloring算法分析 (三)

        HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158     Graph coloring is the problem of assignin ...

随机推荐

  1. SpringMVC入门学习(二)

    SpringMVC入门学习(二) ssm框架 springMVC  在上一篇博客中,我简单介绍了一下SpringMVC的环境配置,和简单的使用,今天我们将进一步的学习下Springmvc的操作. mo ...

  2. Docker系列之Docker镜像(读书笔记)

    一.基本概念 Docker包括三个基本概念镜像.容器.仓库. Docker镜像:就是一个只读的模板.例如:一个镜像可以包含一个完整的ubuntu操作系统环境,里面仅安装了Apache或其他应用程序.用 ...

  3. 前端面试(原生js篇) - 精确运算

    一.面试题 问:开发的时候有用到过 Math 吗? 答:很多啊.比如生成 GUID 的时候,就会用到 Math.random() 来生成随机数. 问:别的呢?比如向下取整.向上取整? 答:向下取整是  ...

  4. 在EXT框架中,使用JS文件设置UEditor文本框,出现新增内容很多,页面变型,不出现滚动条,导致无法进行操作。

    找到UEditor的配置文件:ueditor.config.js(这是我的项目的UEditor的配置文件名) 找到参数设置 autoHeightEnabled 是否自动增长参数,默认为TRUE 当默认 ...

  5. SFTP 文件配置

    sftp_config_file SFTP配置文件(Sublime Text 3 .VS Code) VS Code 的版本 { "host": "120.01.01.1 ...

  6. 前端开发周报: CSS 布局方式方式与JavaScript数据结构和算法

    前端开发周报:CSS 布局方式与JavaScript动画库 1.常见 CSS 布局方式详见: 一些常见的 CSS 布局方式梳理,涉及 Flex 布局.Grid 布局.圣杯布局.双飞翼布局等.http: ...

  7. 【读书笔记】iOS-storyboard-两个场景间的切换(二)

    接着上一节 一,在storybord画布上面,新增加一个场景,即拖动一个View Controller到画布上面,同时建立一个button,名字为secondButton.如图所示. 二,点击第一个按 ...

  8. 【读书笔记】iOS-iPad与iPhone

    在开发通用型应用的时候,你总是需要记住,iPad并不是一个大大的iPod touch,为iPad开发的应用的界面应该更好地利用iPad的大屏幕,而不应该是iPhone应用的复制品. 参考资料:< ...

  9. for each....in、for in、for of

    一.一般的遍历数组的方法: var array = [1,2,3,4,5,6,7]; for (var i = 0; i < array.length; i) { console.log(i,a ...

  10. 第一个React Native程序踩到的那些坑

    毫不夸张的说用React Native写一个Hello World !程序是我碰到最复杂的Hello World.网络上的有关的环境搭建相关的文档也很多,但是总是有这样那样的问题. 官方中文版的安装文 ...