题意就是有n个队伍和m个题目

给出了每个队伍解决的题目数量

每个题目也给出了被解决的次数

然后求一个方阵。

N,Y表示每个队伍是否过了哪个题目。

要求字典序最小。

这题给人的第一反应就是网络流。

虽然用网络流并不是最优算法。

但绝对是最直观的。

行和列分成两部分点。

源点向行连边。

行向列连边

列向终点连边

就行了

然后字典序要求最小。

那么就要枚举删边了。

我们先跑一遍网络流

然后从方阵左上角开始枚举。

每到一个枚举的位置,如果这个位置在第一次跑的网络流中就没有流量的话。显然这个位置可以放N

如果这个位置跑流量了,就要试着删边找增广了

将此边删除。 然后建两个新的源和汇。

源向行标号连一个1容量的边

列标号向新的汇连一个1容量的边

然后我们求新源汇的最大流

如若流量大于0,说明找到增光,此边可删,就删掉边,这个位置放N

否则这位置就Y。 不过同样把边删掉,以防以后找增广找到这。

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <vector>
#define eps 1e-8
#define MAXN 366
#define MAXM 51111
#define INF 111111111
using namespace std ;
int nt, m;
int t[MAXN], p[MAXN];
struct Edge
{
int v, next;
int w;
}edge[MAXM];
int head[MAXN], e;
int id[MAXN][MAXN];
void init()
{
memset(head, -1, sizeof(head));
e = 0;
}
inline void add(int u, int v, int w)
{
edge[e].v = v;
edge[e].w = w;
edge[e].next = head[u];
head[u] = e++;
edge[e].v = u;
edge[e].w = 0;
edge[e].next = head[v];
head[v] = e++;
}
int h[MAXN], gap[MAXN];
int src, des, n;
int dfs(int pos, int cost)
{
if(pos == des) return cost;
int j, minh = n - 1;
int lv = cost, d;
for(j = head[pos]; j != -1; j = edge[j].next)
{
int v = edge[j].v;
int w = edge[j].w;
if(w > 0)
{
if(h[v] + 1 == h[pos])
{
if(lv < edge[j].w) d = lv;
else d = edge[j].w;
d = dfs(v, d);
edge[j].w -= d;
edge[j ^ 1].w += d;
lv -= d;
if(h[src] >= n) return cost - lv;
if(lv == 0) break;
}
if(h[v] < minh) minh = h[v];
}
}
if(lv == cost)
{
--gap[h[pos]];
if(gap[h[pos]] == 0) h[src] = n;
h[pos] = minh + 1;
++gap[h[pos]];
}
return cost - lv;
}
int sap()
{
int ret = 0;
memset(gap, 0, sizeof(gap));
memset(h, 0, sizeof(h));
//gap[0] = n;
while(h[src] < n) ret += dfs(src, INF);
return ret;
}
char out[MAXN][MAXN];
int S, T;
bool ok(int t1, int t2)
{
int k = id[t1][t2];
if(edge[k].w == 1)
{
edge[k].w = 0;
return true;
}
edge[k ^ 1].w = 0;
src = S;
des = T;
int e1 = e;
add(S, t1, 1);
int e2 = e;
add(t2 + nt, T, 1);
if(sap()){
edge[e1 ^ 1].w = edge[e2 ^ 1].w = 0;
return true;
}
edge[e1].w = edge[e2].w = 0;
return false;
}
int main()
{
//freopen("C:/D.in", "r", stdin);
//freopen("C:/DD.out", "w", stdout);
int cas = 0;
while(scanf("%d%d", &nt, &m) != EOF)
{
if(nt == 0 && m == 0) break;
if(cas) puts("");
cas++;
int sum1 = 0, sum2 = 0;
init();
for(int i = 1; i <= nt; i++)
{
scanf("%d", &t[i]);
sum1 += t[i];
}
for(int j = 1; j <= m; j++)
{
scanf("%d", &p[j]);
sum2 += p[j];
}
if(sum1 != sum2)
{
puts("Impossible");
continue;
}
src = nt + m + 1;
des = nt + m + 2;
S = nt + m + 3;
T = nt + m + 4;
n = T;
for(int i = 1; i <= nt; i++)
for(int j = 1; j <= m; j++)
{
id[i][j] = e;
add(i, j + nt, 1);
}
for(int i = 1; i <= nt; i++)
add(src, i, t[i]);
for(int i = 1; i <= m; i++)
add(i + nt, des, p[i]);
int ans = sap();
if(ans != sum1)
{
puts("Impossible");
continue;
} for(int i = 1; i <= nt; i++)
for(int j = 1; j <= m; j++)
{
if(ok(i, j)) putchar('N');
else putchar('Y');
if(j == m) printf("\n");
}
}
return 0;
}

UVALive 4957 Fake scoreboard的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. Fake chat script for website download

    Are you searching for free fake webchat script then you are at the right place go get download your ...

  5. fake gucci outlet perform a couple associated with things in great trust

    Based on my a lot of years of encounter within Taobao, purchase bags must go to the high reputation ...

  6. Zyxel Switch-How to block a fake DHCP server without enabling DHCP snooping?

    How to block a fake DHCP server without enabling DHCP snooping? Scenario How to block a fake DHCP se ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. Redis的AOF功能

    引言:  Redis是基于内存的数据库,同时也提供了若干持久化的方案,允许用户把内存中的数据,写入本地文件系统,以备下次重启或者当机之后继续使用.本文将描述如何基于Redis来设置AOF功能 什么是R ...

  2. Java中的浅复制和深复制 Cloneable clone

    先看一个简单案例 public class Test {     public static void main(String args[]) {         Student stu1 = new ...

  3. datagrid加下拉列表dropdownlist

    datagrid中代码: <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAli ...

  4. VB 增强的部件与引用

    常用部件 对话框 Microsoft Common Dialog Control 6.0 (sp6) COMDLG32.OCX Forms2.0控件        Microsoft Forms 2. ...

  5. PHP 网页爬虫

    只能爬一个页面 <?php function get_urls($url){ $url_array=array(); $the_first_content=file_get_contents($ ...

  6. ASP.NET MVC 几种 Filter 的执行过程源码解析

    一.前言 之前也阅读过MVC的源码,并了解过各个模块的运行原理和执行过程,但都没有形成文章(所以也忘得特别快),总感觉分析源码是大神的工作,而且很多 人觉得平时根本不需要知道这些,会用就行了.其实阅读 ...

  7. List、Set、Map的使用

    1.List(接口) List接口的特点: a.List接口可以存放任意数据,且在接口中,数据可以重复. b.List中提供了高效的插入和移除多个元素的方法. List常用的子类 a.ArrayLis ...

  8. svn更新

    下载配置文件 pwd cd /home/www/xxxx/protected/config/ get main.php 上传配置文件 put main.php svn更新 svn co svn://s ...

  9. 初学Javascript对象

    <script> var p=new Object(); //属性 p.width=; p.height=; p.num=; p.autotime=; //方法 p.autoplay=fu ...

  10. 兄弟连王牌PHP课程送三重豪礼啦!

    兄弟连PHP就业办课程送三重豪礼啦! 惊喜一:报名9月23日班级,保障薪资直涨1000元! 9月报名学习,春节后就业,正是企业招聘的黄金高峰期,一年中拿到高薪最好的时节! 惊喜二:兄弟连云课堂900元 ...