嘟嘟嘟




求无向图的最大独立集。

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

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

然后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. SQL 时间段转换格式

    ), ): :57AM ), ): ), ): ), ): ), ): ), ): ), ): ), ): , ), ): :: ), ): :::827AM ), ): ), ): ), ): ), ...

  2. TCP服务器/客户端代码示例

    TCP服务器代码: #include <errno.h> #include <string.h> #include <stdlib.h> #include < ...

  3. html页面边框的简单设置方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. C# Select

  5. blfs(systemv版本)学习笔记-安装、配置和使用wpa_supplicant无线网络连接工具

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! wireless项目地址:http://www.linuxfromscratch.org/blfs/view/8.3/basic ...

  6. node.js入门学习笔记整理

    (1)node Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node与javaScript的区别在于,javaScript的顶层对象是window,而no ...

  7. WANem广域网环境模拟

    背景 在测试过程中,往往需要模拟网络环境较差情况下,体验情况,故引入广域网模拟工具辅助测试 安装WANem 步骤1:光盘引导WANem镜像: 步骤2:启动(或者新建虚拟机——选择other insal ...

  8. (网页)人人都会的35个Jquery小技巧

    转自CSDN: 收集的35个 jQuery 小技巧/代码片段,可以帮你快速开发. 1. 禁止右键点击 $(document).ready(function(){ $(document).bind(&q ...

  9. [20180408]那些函数索引适合字段的查询.txt

    [20180408]那些函数索引适合字段的查询.txt --//一般不主张建立函数索引,往往是开发的无知,使用trunc等函数,实际上一些函数也可以用于字段的查询.--//以前零碎的写过一些,放假看了 ...

  10. C#微信公众号开发——获取access_token

    access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.正常情况下access_token有效期为7200秒(两个小时),微信获取access_token接 ...