poj 3155 Hard Life

Hard Life
Time Limit: 8000MS Memory Limit: 65536K
Total Submissions: 8495 Accepted: 2468
Case Time Limit: 2000MS Special Judge

Description

John is a Chief Executive Officer at a privately owned medium size company. The owner of the company has decided to make his son Scott a manager in the company. John fears that the owner will ultimately give CEO position to Scott if he does well on his new manager position, so he decided to make Scott’s life as hard as possible by carefully selecting the team he is going to manage in the company.

John knows which pairs of his people work poorly in the same team. John introduced a hardness factor of a team — it is a number of pairs of people from this team who work poorly in the same team divided by the total number of people in the team. The larger is the hardness factor, the harder is this team to manage. John wants to find a group of people in the company that are hardest to manage and make it Scott’s team. Please, help him.

In the example on the picture the hardest team consists of people 1, 2, 4, and 5. Among 4 of them 5 pairs work poorly in the same team, thus hardness factor is equal to 54. If we add person number 3 to the team then hardness factor decreases to 65.

Input

The first line of the input file contains two integer numbers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 1000). Here n is a total number of people in the company (people are numbered from 1 to n), and m is the number of pairs of people who work poorly in the same team. Next m lines describe those pairs with two integer numbers ai and bi (1 ≤ aibi ≤ nai ≠ bi) on a line. The order of people in a pair is arbitrary and no pair is listed twice.

Output

Write to the output file an integer number k (1 ≤ k ≤ n) — the number of people in the hardest team, followed by k lines listing people from this team in ascending order. If there are multiple teams with the same hardness factor then write any one.

Sample Input

sample input #1
5 6
1 5
5 4
4 2
2 5
1 2
3 1

sample input #2
4 0

Sample Output

sample output #1
4
1
2
4
5

sample output #2
1
1

Hint

Note, that in the last example any team has hardness factor of zero, and any non-empty list of people is a valid answer.

Source

提示

题意:

约翰在公司作为高层管理人员,一个富二代将在他手下工作,富二代需要一个团队,团队人员由你分配,为了防止富二代的功绩超过自己,所以约翰将在n(1<=n<=100)个人中选出一部分人组成团队,这几个人之间有m(0<=m<=1000)对人对对方不满,请你为他求出这些人中选出团队最没有默契,即关系数除于人数的值最大,输出人数以及他们的编号。

思路:

裸的最大密集子图

最小割模型在信息学竞赛中的应用.ppt:http://wenku.baidu.com/link?url=sw3qZs2JhgGdDn4skXnoLQysPx-XL3IP3VfzoMgeXc0H8-JsCfxbw7RgMwTwufQo2wuzIATdAPUKyprtKea7quU2JFR4SMxIKQBn4kjFNme

该ppt中d为该点的度,U取m,即边的数量,g为mid(二分的中间值)

个人观点,这样的题做的少,如有错还请见谅。

最小割模型在信息学竞赛中的应用.pdf:http://www.doc88.com/p-941563659710.html

01分数规划:http://blog.csdn.net/hhaile/article/details/8883652

利用01分数规划找出最值。

示例程序

Source Code

Problem: 3155		Code Length: 3284B
Memory: 572K		Time: 94MS
Language: GCC		Result: Accepted
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX 1e9+7
struct
{
    int u,v;
}p[1000];
struct
{
    int v,next;
    double val;
}w[8000];
int h[102],numw,deep[102],du[102],v[102],num;
void insert(int u,int v,double val)
{
    w[numw].v=v;
    w[numw].val=val;
    w[numw].next=h[u];
    h[u]=numw;
    numw++;
    w[numw].v=u;
    w[numw].val=0;
    w[numw].next=h[v];
    h[v]=numw;
    numw++;
}
double min(double x,double y)
{
    if(x>y)
    {
        return y;
    }
    else
    {
        return x;
    }
}
double eps(double x)
{
    return fabs(x)<1e-5?0:x;
}
void build(double val,int n,int m)			//建边
{
    int i;
    for(i=0;m>i;i++)
    {
        insert(p[i].u,p[i].v,1);
        insert(p[i].v,p[i].u,1);
    }
    for(i=1;n>=i;i++)
    {
        insert(0,i,m);
        insert(i,n+1,m+val*2-du[i]);
    }
}
int bfs(int s,int t)
{
    int i,q[40000],top=0,f=0;
    memset(deep,0,sizeof(deep));
    deep[s]=1;
    q[top]=s;
    top++;
    while(f<top)
    {
        if(q[f]==t)
        {
            return 1;
        }
        for(i=h[q[f]];i!=-1;i=w[i].next)
        {
            if(deep[w[i].v]==0&&eps(w[i].val)>0)
            {
                q[top]=w[i].v;
                top++;
                deep[w[i].v]=deep[q[f]]+1;
            }
        }
        f++;
    }
    return 0;
}
double dfs(int s,int t,double max)
{
    int i,pos;
    double val,temp=0;
    if(s==t)
    {
        return max;
    }
    for(i=h[s];i!=-1;i=w[i].next)
    {
        pos=w[i].v;
        val=w[i].val;
        if(deep[s]+1==deep[pos]&&eps(val)>0)
        {
            val=dfs(pos,t,min(max-temp,val));
            w[i].val=w[i].val-val;
            w[i^1].val=w[i^1].val+val;
            temp=temp+val;
            if(temp==max)
            {
                break;
            }
        }
    }
    return temp;
}
double dinic(int s,int t)
{
    double sum=0;
    while(bfs(s,t)==1)
    {
        sum=sum+dfs(s,t,MAX);
    }
    return sum;
}
void find(int t,int n)
{
    int i;
    for(i=h[t];i!=-1;i=w[i].next)
    {
        if(v[w[i].v]==0&&eps(w[i].val)>0)
        {
            v[w[i].v]=1;
            if(w[i].v!=0&&w[i].v!=n+1)
            {
                num++;
            }
            find(w[i].v,n);
        }
    }
}
int main()
{
    int m,n,i,i1;
    double val,r,l,mid,t;
    memset(du,0,sizeof(du));
    scanf("%d %d",&n,&m);
    if(m==0)				//如果没有相互憎恨就输出1
    {
        printf("1\n1");
    }
    else
    {
        for(i=0;m>i;i++)
        {
            scanf("%d %d",&p[i].u,&p[i].v);
            du[p[i].u]++;
            du[p[i].v]++;
        }
        r=m;
        l=0;
        while(r-l>1.0/n/n)			//二分求解(1.0/(n^2)即可)
        {
            memset(h,-1,sizeof(h));
            numw=0;
            mid=(r+l)/2;
            build(mid,n,m);
            t=dinic(0,n+1);
            t=(n*m*1.0-t)/2;
            if(t>1e-5)
            {
                l=mid;
            }
            else
            {
                r=mid;
            }
        }
        memset(h,-1,sizeof(h));
        memset(v,0,sizeof(v));
        numw=0;
        build(l,n,m);
        t=dinic(0,n+1);
        num=0;
        find(0,n);
        printf("%d\n",num);
        for(i=1;n>=i;i++)
        {
            if(v[i]==1)
            {
                printf("%d\n",i);
            }
        }
    }
    return 0;
}

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值