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 ...
随机推荐
- [转载]MongoDB 常用命令
mongodb由C++编写,其名字来自humongous这个单词的中间部分,从名字可见其野心所在就是海量数据的处理.关于它的一个最简洁描述为:scalable, high-performance, o ...
- Python/Numpy大数据编程经验
Python/Numpy大数据编程经验 1.边处理边保存数据,不要处理完了一次性保存.不然程序跑了几小时甚至几天后挂了,就啥也没有了.即使部分结果不能实用,也可以分析程序流程的问题或者数据的特点. ...
- Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
章出自:luchg技术交流 http://www.luchg.com 版权所有.本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源,谢谢. Android-java.lang.Runti ...
- IBM
http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1306mongodb2/
- POJ 2186 Popular Cows(Tarjan)
http://poj.org/problem?id=2186 题意 :给你n头牛,m对关系,每对关系由两个编号组成,u和v代表着u认为v是受欢迎的,如果1认为2是受欢迎的,2认为3是受欢迎的,那1认为 ...
- c++学习之旅-Cygwin+Eclipse ide for c++
一,cygwin下载完毕后配置系统环境片两path指向cygwin/bin 二,eclipse设置 2.1 设置工作目录的cygwin映射 cygwin/d ->d:\ 2.2设置编译 下面新建 ...
- Maven内置变量
1.Maven内置变量说明: ${basedir} 项目根目录 ${project.build.directory} 构建目录,缺省为target ${project.build.outputDire ...
- loadrunner 脚本和replaylog中的中文乱码问题(转载)
解决这个问题必须认识到一个事实就是,loadrunner和测试服务器交换数据使用的是utf8格式,但是展现在replaylog中是使用gb2312格式,而且在脚本中如何使用web_reg_find的时 ...
- Ember.js demo2
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1 ...
- c while 循环
c代码: #include <stdio.h> int main(void){ unsigned long sum=1UL; unsigned int j=1U; unsigned ; p ...