【HDU6150】Vertex Cover (构造)

来源:互联网 发布:淘宝闲鱼拍卖靠谱吗 编辑:程序博客网 时间:2024/06/09 19:10

这道题是一道神奇的构造,直接看代码吧,构造方法很好理解。


#include <iostream>#include <cstdio>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <string>#include <cstring>#include <map>using namespace std;struct node{    int tag, du;    bool operator < (const node& ano) const    {        return du > ano.du;    }}nodes[100];int main(){    printf("148 900\n");    for(int i = 0; i < 30; ++i)    {        nodes[i].tag = i + 1;        nodes[i].du = 30;    }    for(int i = 31; ; ++i)    {        sort(nodes, nodes + 50);        if(nodes[0].du == 0) break;        else        {            int cnt = nodes[0].du;            for(int j = 0; j < cnt; ++j)            {                printf("%d %d\n", i, nodes[j].tag);                nodes[j].du -= 1;            }        }    }    printf("30\n");    for(int i = 1; i <= 30; ++i)        printf("%d\n", i);    return 0;}