SGU 218.Unstable Systems
题意:
有n(n<500)台机器,和500个程序。不同的程序在不同的机器上运行有着不同的不稳定度s[i][j]。求最小的最大稳定度及其方案。
Solution:
比较经典的二分图模型。
建图很简单。直接将$s[i][j]$作为图的邻接矩阵。
看到求最小的最大稳定度,想到二分答案。
check的话,只要利用所有小于等于当前二分的$ans$的边求二分图的最大匹配。如果$ 最大匹配=n $ 那么当前解是可行的。
十分要注意的是权值可能为负!
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 501;
int link[N], vis[N];
int G[N][N],ans[N];
int n, mid;
bool DFS ( int x )
{
for ( int i = 1; i <= n; i++ )
if ( G[x][i] <= mid && !vis[i] ) {
vis[i] = 1;
if ( link[i] == -1 || DFS ( link[i] ) ) {
link[i] = x;
return 1;
}
}
return 0;
}
bool check()
{
int ans = 0;
memset ( link, -1, sizeof link );
for ( int i = 1; i <= n; i++ ) {
memset ( vis, 0, sizeof vis );
if ( DFS ( i ) ) ans++;
}
return ans == n;
}
int main()
{
scanf ( "%d", &n );
for ( int i = 1; i <= n; ++i ) {
for ( int j = 1; j <= n; ++j ) {
scanf ( "%d", &G[i][j] );
}
}
int l = -int(1e6), r = int ( 1e6 );
while ( l <= r ) {
mid = ( l + r ) >> 1;
if ( check () ) r = mid - 1;
else
l = mid + 1;
}
printf ( "%d\n", r + 1 );
mid = r + 1;
check();
for ( int i = 1; i <= n; ++i ) {
ans[link[i]]=i;
}
for ( int i = 1; i <= n; ++i ) {
printf ( "%d %d\n", i, ans[i] );
}
}
/*
3
100 1 100
100 100 1
1 100 100
*/
SGU 218.Unstable Systems的更多相关文章
- Gromacs命令-Chapter1
Gromacs的命令非常多,下面我将我最近用到的先总结一下.标题上也写了这只是Chapter1,以后有新的会继续写Chapter2...等等. 下面这个网址http://manual.gromacs. ...
- 【SGU 390】Tickets (数位DP)
Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell ...
- Virtualization solutions on Linux systems - KVM and VirtualBox
Introduction Virtualization packages are means for users to run various operating systems without &q ...
- Methods and systems for sharing common job information
Apparatus and methods are provided for utilizing a plurality of processing units. A method comprises ...
- PatentTips - Systems, methods, and devices for dynamic resource monitoring and allocation in a cluster system
BACKGROUND 1. Field The embodiments of the disclosure generally relate to computer clusters, and m ...
- Single-stack real-time operating system for embedded systems
A real time operating system (RTOS) for embedded controllers having limited memory includes a contin ...
- Android Weekly Notes Issue #218
Android Weekly Issue #218 August 14th, 2016 http://androidweekly.net/issues/issue-218 ARTICLES & ...
- Modern Operating Systems(Ⅰ)——2014.12.15
进程 进程模型 进程就是一个正在执行的程序的实例 值得注意的是,若一个程序运行了两遍,则算作两个进程 创建进程 在通用系统中,有四种主要事件导致进程的创建 ①系统的初始化 ②执行了 正在 ...
- 【转载】Bandits for Recommendation Systems (Part I)
[原文链接:http://engineering.richrelevance.com/bandits-recommendation-systems/.] [本文链接:http://www.cnblog ...
随机推荐
- [读书笔记]算法(Sedgewick著)·第二章.初级排序算法
本章开始学习排序算法 1.初级排序算法 先从选择排序和插入排序这两个简单的算法开始学习排序算法.选择排序就是依次找到当前数组中最小的元素,将其和第一个元素交换位置,直到整个数组有序. public s ...
- firefox和chrome对于favicon.ico关于content-security-policy的不同处理
1.favicon.ico是网站的title图标 2.在设置CSP时,举例如下,表示只允许来源为https://my.alipay.com的图片,如果不是,则向指定的url(report.php)发出 ...
- POJ 2728 Desert King
Description David the Great has just become the king of a desert country. To win the respect of his ...
- linux中删除目录
在linux中删除一个目录很简单,很多人还是习惯用rmdir,不过一旦目录非空,就陷入深深的苦恼之中,现在使用rm -rf命令即可解决. 直接rm就可以了,不过要加两个参数-rf 即:rm -rf 目 ...
- 读取xml格式文件
$v = [xml]get-content d:\vmconfig.xml $v.Domain.Computer.Name =========================== $v.GetElem ...
- 分页存储过程--From:桌面备份 -> sql2005新功能.docx
二.以下示例将返回行号为 50 到 60(含)的行,并以 OrderDate 排序. USE AdventureWorks; GO WITH OrderedOrders AS (SELECT Sale ...
- PHP class_exists 检查类是否已定义
(PHP 4, PHP 5) class_exists — 检查类是否已定义 bool class_exists ( string $class_name [, bool $autoload ] ) ...
- Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
加入jar包 http://jarfiles.pandaidea.com/google.collect.html google-collect-1.0.jar.zip ( 504.8 KB )
- 详解QUiLoader 动态加载.ui文件
http://blog.chinaunix.net/uid-13838881-id-3652523.html 1.适用情况: 动态加载UI文件是指,用 Qt Designer 通过拖拽的方式生产.ui ...
- opai_suki