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 ...
随机推荐
- 使用WampServer 3.0
在server上安装了WampServer 发现本地使用良好,但是无法从别的PC访问. 原因有二: 1.现象:输入连接无反应 原因:server本身用了80端口,所有WampServer我就设置了80 ...
- SHELL学习笔记----IF条件判断,判断条件
SHELL学习笔记----IF条件判断,判断条件 前言: 无论什么编程语言都离不开条件判断.SHELL也不例外. if list then do something here ...
- Spring MVC使用commons fileupload实现文件上传功能
通过Maven建立Spring MVC项目,引入了Spring相关jar依赖. 1.为了使用commons fileupload组件,需要在pom.xml中添加依赖: <properties&g ...
- POJ3714+最近点对
特判标记即可 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h& ...
- 【 NOIP2015 DAY1 T2 信息传递】带权并查集
题目描述 有n个同学(编号为1到n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为i的同学的信息传递对象是编号为Ti同学. 游戏开始时,每人都只知道自己的生日.之后每一 ...
- Java集合类之向量Vector
package com.test; import java.util.*; public class Demo7_3 { public static void main(String[] args) ...
- Cookie的前后台应用
1.jquery.cookie.js的基本应用 这个是第三方js插件,可以更方便的设置和使用cookie $.cookie("UserName", "kingtiger& ...
- uiview scale
http://stackoverflow.com/questions/3946797/cgaffinetransformmakescale-makes-uiview-jump-to-original- ...
- MVC中的扩展点(六)ActionResult
ActionResult是控制器方法执行后返回的结果类型,控制器方法可以返回一个直接或间接从ActionResult抽象类继承的类型,如果返回的是非ActionResult类型,控制器将会将结果转换为 ...
- 动态修改log4net组件的日志文件名
最近项目使用到log4net来记录日志,当然二话不说先到cnblogs上查看一下各位高手关于log4net的教程和心得主要参看了摩诘 的Log4Net使用指南 (确实是非常好的log4net的入门指南 ...