HDU 6150 Vertex Cover (构造)

网友投稿 876 2022-10-03

HDU 6150 Vertex Cover (构造)

HDU 6150 Vertex Cover (构造)

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 ​​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]; } returnAs 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 500 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.

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 next m 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 integer k(1≤k≤n), means the size of your vertex cover solution.Then output k 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.

Sample Output

4 41 22 33 44 1213

题意

在解决最小顶点覆盖问题时有一种贪心算法总是挑选度最大的节点删去,但是这种算法是错误的,我们需要构造一组数据使得其误差至少是正确结果的三倍。

思路

我们把所有的点分成两部分,左边的点为正确结果需要选取的部分,右边的点为贪心算法的结果。

然后对左边的点进行 ​​n​​ 次分块,块大小分别为 1..2..3..n

对于每一次分得的大小为 x 的块,我们新建右边的一个节点与这 x

最终的结果是,左边的节点只有一个度为 n 的点,其余节点度都小于 n ,右边也一样,我们看到贪心算法中总是选取度最大编号最大的节点删掉,于是我们在编号时将左边的节点分别编号为 ​​1-n​​​ ,右边为 ​​n+1-...​​ ,这样构建出的图在贪心解法中一定总是选取右边的节点。

接下来便是确定一个合适的 ​​n​​ 使得两边点的数量倍数满足题意即可。

PS:要是这道题出在蓝桥杯的填空题会怎么样呢?

AC 代码

#includeusing namespace std;const int maxn = 1e6+10;typedef __int64 LL;typedef pair P;const int mod = 1e9+7;P e[maxn];int tot,st;void solve(int n){ st = n; for(int i=2; i<=n; i++) { for(int j=0; j

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信小程序实现滚动加载数据(微信小程序实现滚动加载数据的方式)
下一篇:小程序消息推送配置案例(小程序消息推送配置怎么填写)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~