嘟嘟嘟




求无向图的最大独立集。

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

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

然后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. Jenkins持续集成学习-Windows环境进行.Net开发2

    目录 Jenkins持续集成学习-Windows环境进行.Net开发2 目录 前言 目标 使用 .Net Stardard 单元测试 流程 手动执行单元测试 自动执行单元测试 单元测试报告 上传Nug ...

  2. Vue2.5开发去哪儿网App 详情页面开发

    一,banner 图的设计 1. 新建detail的路由 import Detail from '@/pages/detail/Detail' ...... { path: '/detail', na ...

  3. DotNetCore学习-2.程序启动

    新创建的ASP.NET Core程序中包含两个文件,分别是Program.Startup.其中,Program中Main方法是整个应用程序的入口,该方法如下: var host = WebHost.C ...

  4. asp.net前台页面与后台之间传值,

     在前台用 js 获取到的 “值 ”需要传到后台,在后台调用,    ******  原有传入的 “值 ” 不要被覆盖     1.最简单的在页面写一个隐藏表单,隐藏标签,把获取到的值赋给隐藏标签之后 ...

  5. [javaEE] Servlet的手动配置

    一.Servlet sun提供的一种动态web资源开发技术,本质上就是一段java小程序,可以将Sevlet加入到Servlet容器中 *Servlet容器 -- 能够运行Servlet的环境就叫做S ...

  6. 在整合spring和mongodb中,提示at org.springframework.data.mapping.model.BasicPersistentEntity.findAnnotation(

    遇到这种坑,找了好多资料.基本是都是因为springdata的jar包和spring的版本不兼容导致,除了这个错误之外,还有会比较多其他错误,也是版本不兼容导致的. at org.springfram ...

  7. Git 实战手册(一): 批量修改log中的提交信息

    本文须知 教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 背景介绍 事情的起源是这样的:迷恋的谷歌的我最近申请了一个新的 googl ...

  8. Python3 系列之 编程规范篇

    编码规范 编码 如无特殊情况, 文件一律使用 UTF-8 编码 如无特殊情况, 文件头部必须加入 #--coding:utf-8-- 标识 缩进 统一使用 4 个空格进行缩进 引号 自然语言 使用双引 ...

  9. JS之this应用详解

    目录 1. this作为全局变量2. 作为对象方法的调用3. 作为构造函数调用4. apply调用 this是Javascript语言的一个关键字.它代表函数运行时,自动生成的一个内部对象,只能在函数 ...

  10. 卷积神经网络CNNs的理解与体会

    https://blog.csdn.net/shijing_0214/article/details/53143393 孔子说过,温故而知新,时隔俩月再重看CNNs,当时不太了解的地方,又有了新的理解 ...