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 ...
随机推荐
- poj1873 The Fortified Forest 凸包+枚举 水题
/* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...
- css3划过图片闪光
css代码 01 .img { display:block; position: relative; width:800px; height:450px; margin:0 auto;} 02 .im ...
- Android Studio更新失败
解决方案: Windows平台下 如果是运行的Android studio是32位的需要在修改一下文件: 在andriod studio的启动目录下.找到studio.exe.vmoptions这个文 ...
- Linux crontab 命令格式与具体样例
基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...
- careercup-树与图 4.4
4.4 给定一棵二叉树,设计一个算法,创建含有某一深度上所有结点的链表(比如,若一棵树的深度为D,则会创建D个链表). 类似于leetcode:Populating Next Right Pointe ...
- Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】
今日写了个如题目的简单功能,结果列表不显示 无奈重写了一次代码发现setMessage和setSingleChoiceItems不能同时使用. 正确的如下: private void mobilePh ...
- *.pro、*.pri、*.prf、*.prl等四种文件
尽管每次和cmake对比起来,我们总是说 qmake 简单.功能少.但是qmake仍然是一个非常复杂的东西,我想大多人应该和我一样吧: 不是太清楚CONFIG等变量到底如何起作用的 用过的qmak ...
- java coding recommand
http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
- oracle数据库入门sql语句
数据库: 命名规范问题 依然是 _流.看来也确实应该抽空 来处理一下 今天吧,不行时间不能浪费.要更加专注.累了 就睡,醒来 就 好好 弄东西.白天 哪怕累一些,强度 大一些,晚上也可以抽空出去.溜溜 ...
- WINDOWS Server2003上部署一个Asp.Net的网站
对于许多新手来说,如何在服务器上部署网站并不了解,这个教程希望对新手有帮助. 1.IIS服务器 2..Net Framework3.5 (方便起见,我们这里Framework说的都是指的这个版本) 这 ...