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 ...
随机推荐
- javascript中部分不能使用call apply调用来重写的构造函数
This tests if TypeError is thrown or not when we call a constructor as a normal function. On ...
- Hbase 0.96 比 hbase 0.94的改变
转载:http://blog.csdn.net/hxpjava1/article/details/20043703 环境: hadoop:hadoop-2.2.0 hbase:hbase-0.96.0 ...
- XSS之学习误区分析
有段时间没写东西了, 最近看到zone里出现了很多“XSS怎么绕过某某符号的帖子”,觉得很多新手在寻找XSS时走进了一些误区,比如:专门想着怎么去“绕过”.这里做个总结,希望对大家有所帮助. 1. 误 ...
- 周末“干活”之 Mesos Meetup
周末两天都是大雾霾天,作为运营也不能在家宅,告别了技术就得腿儿勤点儿. 非常感谢 Linker 的 Sam Chen 和 数人科技 的 CTO 共同组织的Mesos Meetup,OneAPM 最帅的 ...
- .NET(C#):灵活运用CryptoStream,加密不是必须用CryptoStreamMode.Write
首先.NET中的ICryptoTransform是单向的,也就是只能从一个状态将数据转化成另一个状态,反之是不可以的.当然手动 操作ICryptoTransform还是比较繁琐的,通过CryptoSt ...
- 禁用nginx的access日志
修改nginx.conf 找到access_log: access_log /dev/null; 或者access_log off
- MYSQL SHOW VARIABLES简介
原文地址:http://www.2cto.com/database/201108/100546.html mysqld服务器维护两种变量.全局变量影响服务器的全局操作.会话变量影响具体客户端连接相关操 ...
- java程序执行时,JVM内存
高淇 java 31集 类代码,static,常量池到方法区 (常量池会在类之间共享) 局部变量 到栈 对象到 堆 高淇 32集 增加一个computer类
- asp.net将sql语句封装在类库中
将sql语句封装在cs中,通过类库的引用使用他的select.update.insert 源代码(cs): using System; using System.Collections.Generic ...
- Android 常用UI控件之TabHost(2)简单示例
1,布局 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...