POJ3155 Hard Life
| Time Limit: 8000MS | Memory Limit: 65536K | |
| Total Submissions: 8482 | Accepted: 2461 | |
| 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 5⁄4. If we add person number 3 to the team then hardness factor decreases to 6⁄5.
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 ≤ ai, bi ≤ n, ai ≠ 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
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
const double eqs = 1e- ;
const int N = + , M = + ;
using namespace std ;
int n , m , head[N] , cnt , s , t , du[N] , num , cur[N] , node[N] ;
struct ide
{
int u , v ;
} edge[M] ;
struct id
{
int fro ,nxt , to ; double w ;
} links[] ; void add( int u , int v , double val )
{
links[++cnt].fro = u , links[cnt].to = v ;
links[cnt].nxt = head[u] , links[cnt].w = val , head[u] = cnt ;
} void Init( )
{
scanf( "%d%d" , &n , &m ) ; s = , t = n + ;
for( int x = ; x <= m ; ++x )
{
scanf( "%d%d" , &edge[x].u , &edge[x].v ) ;
++du[edge[x].u] , ++du[edge[x].v] ;
}
} int dis[N] ; queue< int > Q ;
bool bfs( )
{
memset( dis , - , sizeof(dis) ) ;
dis[s] = ; Q.push( s ) ;
while( !Q.empty( ) )
{
int u = Q.front( ) ; Q.pop( ) ;
for( int i = head[u] ; ~i ; i = links[i].nxt )
{
int v = links[i].to ;
if( dis[v] < && fabs( links[i].w ) > eqs )
{
dis[v] = dis[u] + ;
Q.push( v ) ;
}
}
}
return dis[t] != - ;
} double dfs( int u , double f )
{
if( u == t ) return f ;
double an , cost = 0.00 ;
for( int i = cur[u] ; ~i ; i = links[i].nxt )
{
int v = links[i].to ;
if( dis[v] != dis[u] + ) continue ;
an = dfs( v , min( f - cost , links[i].w ) ) ;
cost += an ; links[i^].w += an , links[i].w -= an ;
if( fabs( links[i].w ) > eqs ) cur[u] = i ;
if( fabs( cost - f ) < eqs ) return cost ;
}
if( fabs( cost ) < eqs ) dis[u] = - ;
return cost ;
} double Dinic( )
{
double ans = 0.00 ;
while( bfs( ) )
{
for( int x = s ; x <= t ; ++x ) cur[x] = head[x] ;
ans += dfs( s , ) ;
}
//cout<<ans<<endl;
return ans ;
} double check( double mid )
{
//cout<<mid<<endl;
cnt = - ; memset( head , - , sizeof(head) ) ;
for( int i = ; i <= n ; ++i )
{ add( s , i , m*1.0 ) , add( i , s , ) ;
add( i , t , m + * mid - du[i] ) ;
add( t , i , ) ;
}
for( int i = ; i <= m ; ++i )
{
add( edge[i].u , edge[i].v , 1.0 ) ;
add( edge[i].v , edge[i].u , 0.0 ) ;
add( edge[i].v , edge[i].u , 1.0 ) ;
add( edge[i].u , edge[i].v , 0.0 ) ;
}
return Dinic( ) ;
} bool vis[N] ;
void flow( int u )
{
vis[u] = true ;
if( u >= && u <= n ) node[++num] = u ;
for( int i = head[u] ; ~i ; i = links[i].nxt )
if( links[i].w > && !vis[links[i].to] ) flow( links[i].to ) ;
} void Solve( )
{
double l = , r = m , minn = 1.00 / n / n ;//cout<<l<<" "<<r<<endl;
while( r - l >= minn )
{
double mid = ( r + l ) / ;
double hg = check( mid ) ; //cout<<l<<" "<<hg<<endl ;
if( ( m * n - hg )* 0.5 > eqs ) l = mid ;
else r = mid ; } check( l ) ; num = ;
flow( s ) ; if( num == ) node[++num] = ;
sort( node + , node + + num ) ;
printf( "%d\n" , num ) ;
for( int x = ; x <= num ; ++x ) printf( "%d\n" , node[x] ) ;
} int main( )
{
// freopen( "poj3155.in" , "r" , stdin ) ;
// freopen( "poj3155.out" , "w" , stdout ) ;
Init( ) ;
Solve( ) ;
// fclose( stdin ) ;
// fclose( stdout ) ;
return ;
}
POJ3155 Hard Life的更多相关文章
- Bzoj1312 / POJ3155 Neerc2006 Hard Life
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 459 Solved: 114 Description 在一家公司中,人事部经理与业务部经理不和.一次 ...
- 最大密集子图(01分数规划+二分+最小割)POJ3155
题意:给出一副连通图,求出一个子图令g=sigma(E)/sigma(V); h[g]=sigma(E)-g*sigma(V):设G是最优值 则当h[g]>0:g<G h[g]<0, ...
- POJ3155 Hard Life [最大密度子图]
题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...
- poj3155 最大密度子图
求最大密度子图 记得在最后一次寻找的时候记得将进入的边放大那么一点点,这样有利于当每条边都满流的情况下会选择点 #include <iostream> #include <algor ...
- 【POJ3155】生活的艰辛Hard Life
题面 Description ADN公司内部共 n个员工,员工之间可能曾经因为小事有了过节,总是闹矛盾.若员工u和员工 v有矛盾,用边(u, v)表示,共 m个矛盾.最近,ADN公司内部越来越不团结, ...
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
随机推荐
- [转载]初学C#之list
C# List<T>用法 所属命名空间:System.Collections.Generic public class List<T> : IList<T>, IC ...
- LFI & RFI & PHP封装协议之安全问题研究
目录 . 文件包含的基本概念 . LFI(Local File Include) . RFI(Remote File Include) . PHP中的封装协议(伪协议).PHP的流式文件操作模式所带来 ...
- HDU1632+半平面交
模板题 题意:给定两个凸多边形,求出合并后的面积,这个合并后的面积不包括重叠部分. #include<stdio.h> #include<string.h> #include& ...
- Java使用socket实现两人聊天对话
import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner; /* ...
- [线段树]HDOJ5091 Beam Cannon
题意:给n, w, h (1 <= N <= 10000,1 <= W <= 40000,1 <= H <= 40000) $w\times h$是可以射到的范围 ...
- yii
2008年出现的一个以php为基础的框架,特点是:高性能框架.代码重用性.速度非常快(改完代码后直接刷新就可以展示修改后的页面).有小物件.登录组件.日志组件等等. main.php配置与数据库相连的 ...
- [转]C,C++开源项目中的100个Bugs
[转]C,C++开源项目中的100个Bugs http://tonybai.com/2013/04/10/100-bugs-in-c-cpp-opensource-projects/ 俄罗斯OOO P ...
- cat主要有三大功能
cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > filename 只能创建新文件,不能编辑已有文件.3.将几个文件合并为一 ...
- 屏幕尺寸,屏幕分辨率,屏幕密度,各种长宽单位(px,sp,dp,in.pt,mm)
常见长宽单位表 名称 单位缩写 单位全拼 介绍 屏幕尺寸 '' 或 in inch 屏幕的大小,通常用屏幕对角线的长度表示.单位是寸 屏幕分辨率 px pixels 整个屏幕的像素数,一般用屏幕的像素 ...
- 【Python】代码行数统计
两级目录,可扩展为N级. # Count the line of dir or file import os, fnmatch, fileinput def ChkFileType(lst): tmp ...