HDU 6150 Vertex Cover 构造
来源:互联网 发布:苹果手机变音软件 编辑:程序博客网 时间:2024/06/10 02:36
题目链接:HDU6150
Vertex Cover
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 505 Accepted Submission(s): 197
Special Judge
Problem Description
As we know, minimumvertexcover is a classical NP-complete problem. There will not be polynomial time algorithm for it unless P=NP .
You can see the definition of vertex cover in https://en.wikipedia.org/wiki/Vertex_cover.
Today, little M designs an "approximate" algorithm for vertex cover. It is a greedy algorithm. The main idea of her algorithm is that always choosing the maximum degree vertex into the solution set. The pseudo code of her algorithm is as follows:
We assume that the labels of the vertices are from 1 to n.
As a theory computer scientist, you immediately find that it is a bad algorithm. To show her that this algorithm dose not have a constant approximate factor, you need to construct an instance of vertex cover such that the solution get by this algorithm is much worse than the optimal solution.
Formally, your program need to output a simple undirected graph of at most500 vertices. Moreover, you need to output a vertex cover solution of your graph. Your program will get Accept if and only if the solution size get by the above algorithm is at least three times as much as yours.
You can see the definition of vertex cover in https://en.wikipedia.org/wiki/Vertex_cover.
Today, little M designs an "approximate" algorithm for vertex cover. It is a greedy algorithm. The main idea of her algorithm is that always choosing the maximum degree vertex into the solution set. The pseudo code of her algorithm is as follows:
We assume that the labels of the vertices are from 1 to n.
for (int i = 1; i <= n; ++i) { use[i] = false; deg[i] = degree of the vertex i;}int ans = 0;while (true) { int mx = -1, u; for (int i = 1; i <= n; ++i) { if (use[i]) continue; if (deg[i] >= mx) { mx = deg[i]; u = i; } } if (mx <= 0) break; ++ans; use[u] = true; for (each vertex v adjacent to u) --deg[v];}return ans;
As a theory computer scientist, you immediately find that it is a bad algorithm. To show her that this algorithm dose not have a constant approximate factor, you need to construct an instance of vertex cover such that the solution get by this algorithm is much worse than the optimal solution.
Formally, your program need to output a simple undirected graph of at most
Input
There is no input.
Output
First, output two integer n and m in a line, separated by a space, means the number of the vertices and the number of the edges in your graph.
In the nextm lines, you should output two integers u and v for each line, separated by a space, which denotes an edge of your graph. It must be satisfied that 1≤u,v≤n and your graph is a simple undirected graph.
In the next line, output an integerk(1≤k≤n) , means the size of your vertex cover solution.
Then outputk lines, each line contains an integer u(1≤u≤n) which denotes the label of a vertex in your solution. It must be satisfied that your solution is a vertex cover of your graph.
In the next
In the next line, output an integer
Then output
Sample Output
4 41 22 33 44 1213HintThe sample output is just to exemplify the output format.
题意:给出一种贪心的求顶点覆盖的方法,现在要求你给出一个图,贪心给出的答案是你的3倍以上。
题目分析:4题末在最后也没有闲鱼翻身。考虑二分图,左面有n个点,一共分n次块,第i次的每块长度是i,不构成一整块的不考虑,
对于每块都新建一个顶点和块内所有点相连,考虑如下图:
参考论文:《最优顶点覆盖的贪心近似算法》
这样答案给出的解都是右边新加的nlogn的点,只需让logn大到3即可。
//// main.cpp// HDU6150 Vertex Cover//// Created by teddywang on 2017/8/21.// Copyright © 2017年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;pair<int, int> p[5000];int n,m;int t[5000];int main(){ n=20; m=0; int pos=n; int num=0; for(int i=1;i<=n;i++) { for(int j=0;j<n/i;j++) { pos++; for(int k=1;k<=i;k++) { p[num++]=make_pair(pos, i*j+k); } } } printf("%d %d\n",pos,num); for(int i=0;i<num;i++) { printf("%d %d\n",p[i].first,p[i].second); } printf("%d\n",n); for(int i=1;i<=n;i++) { printf("%d\n",i); }}
阅读全文
0 0
- HDU 6150 Vertex Cover【构造】
- HDU 6150 Vertex Cover 构造
- HDU 6150 Vertex Cover 构造
- HDU 6150 Vertex Cover (思路 构造)
- HDU-6150 Vertex Cover(构造)
- HDU 6150 Vertex Cover (构造)
- HDU 6150 Vertex Cover【构造二分图】
- hdu 6150 Vertex Cover(构造)
- hdu 6150 Vertex Cover
- HDU 6150 Vertex Cover (有趣的构造)
- Hdu 6150 Vertex Cover【思维】
- 【HDU6150】Vertex Cover (构造)
- HDU 6150 Vertex Cover(二分图)
- HDU6150-Vertex Cover(构造)
- Vertex Cover
- Vertex Cover
- Vertex Cover
- set cover和vertex cover
- 高德地图实现公交路线-添加标记-轨迹回放-中心点-图层
- HTTP/2服务端推送
- WPF DEV PieSeries2D扇形标识线变长充满
- HDU 2087 剪花布条【最长不重复子串】【KMP】【水题】【模板题】
- python居家旅行必备的pyenv,virtualenv
- HDU 6150 Vertex Cover 构造
- python试爬李毅吧贴子标题,爬虫最初级
- python使用scrapy爬表格,爬虫中级
- skynet源码分析(1)--模块加载
- org.springframework.beans.ConversionNotSupportedException异常解决方法
- skynet源码分析(2)--消息队列mq
- skynet源码分析(3)--消息名字和ID之handle
- Unix和Linux有什么区别? 通俗解释
- skynet源码分析(4)--monitor