嘟嘟嘟




求无向图的最大独立集。

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

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

然后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. C# QuartZ使用实例写成服务

    官方学习文档:http://www.quartz-scheduler.net/documentation/index.html 官方的源代码下载:http://sourceforge.net/proj ...

  2. Contest2073 - 湖南多校对抗赛(2015.04.06)

    Contest2073 - 湖南多校对抗赛(2015.04.06) Problem A: (More) Multiplication Time Limit: 1 Sec  Memory Limit:  ...

  3. Gauss-Laguerre quadrature rule

    % matlab script to derive the 2-point Gauss-Laguerre quadrature rule % and use it on an example % in ...

  4. 关于IOS下click事件委托失效的解决方案

    一.由于某些特殊情况下,需要用到事件委托,比如给动态创建的DOM绑定click事件,这里就需要事件委托(这里就牵扯到:目标元素和代理元素)目标元素:动态创建的元素,最终click事件需要绑定到该元素 ...

  5. Django Rest Framework之版本控制

    基本代码结构 settings.py: REST_FRAMEWORK = { 'DEFAULT_VERSION': 'v1', # 默认版本 'ALLOWED_VERSIONS': ['v1', 'v ...

  6. linux学习笔记-开机流程与主引导分区(MBR)

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 读鸟哥的linux私房菜-基础学习篇(第三版)3.2.4章节作此笔记 一.术语介绍: Bios:写入到主板上的一个程序,计算机开 ...

  7. CentOS7系列--安装Chrome浏览器

    CentOS7系列--安装Chrome浏览器 1. 创建yum源文件 [root@server20 ~]# cd /etc/yum.repos.d/ [root@server20 yum.repos. ...

  8. python自动化开发-5a

    python的常用模块 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护.为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包 ...

  9. ARP协议总结

    1.ARP用于实现ip和MAC地址之间的对应关系. 2.ARP的流程主要分为ARP请求.ARP应答.免费ARP. 3.首次ARP请求是广播报文,后续确认的ARP是单播报文. 4.免费ARP有两个用途, ...

  10. Expo大作战(三十一)--expo sdk api之Payments(expo中的支付),翻译这篇文章傻逼了,完全不符合国内用户,我只负责翻译大家可以略过!

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...