toj 1421
题意:假如存在矩阵A,A[i][0] + A[i][1] + ...... + A[i][n - 1] == SR[i],A[0][j] + A[1][j] + ...... + A[n - 1][j] == SC[j].(0 <= A[i][j] <= 100),输出YES并输出任意一个满足条件的矩阵A,若不存在则输出NO
分析:SR[0] + SR[1] + ...... + SR[n - 1] == SC[0] + SC[1] + ...... + SC[n - 1],建图的重点是把银行和公司之间的边的容量都设为100,作为流的上限.
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAncAAAD/CAIAAAAc1GepAAAeNklEQVR4nO2d25WjOhBFicsBOR5H42QcDPPhaQzogZBUUpW098dd0xhL9T5g3H2XFQAAAGRYehsAAAAwLKgsAACAFKgsAACAFKgsAACAFKgsAACAFKgsAACAFKgsAIBeloUpbRvyBwCgF1TWOuQPAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWAABAClQWIJ/P67Esy+P1OR9almVZnu/oQQCYAFQWII/3c1ker/frsVfZ78HP8Z/egwAwBagsQAmfg8q+n7ub1c/rsTzfgYMAMAeoLEAJB5U9Su7/n7wHe5gKAB1AZQFKiKjs+n66Kvv/YHtDAaALqCxACdzLAkAMVBagBJ7LAkAMVBagBPfz4D8R/f3TexAApgCVBcjj/VwO/Nfa36/G7sTXexAAJgCVBQAAkAKVBQAAkAKVBQAAkAKV7cP2MK+3IQCgCCbDeJDL1pxaiI4CgJXJMC5ksTVu59BLAMBkGBWy2JRQ29BOADPDZBgYUtiUSC8BwJykTAbBqQTCkLymuN1yajYAmJDQBNgOMh/sQuZa4xXa7R/uRS4ADEyk5d0fmQkWIWetObWKt3PiHy4BgFFSPj3en+ldoaG9UAES1hT3tnX/o/d8b+8hvQD6uRTRyBX25bIiFoMApKodl40RaZ54X6G7AN1JacOKHUqbW4E8teBWX11qbcpS6C6AKLdaTKgTaW0TkCFx8tog8eb17oJIL8BdsnunTbvRyMohPbIUNkD6NXLJ+uguwEZ5U5ze2KCtaF7NkBgpKtZ9ylK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tmMR9tRXzfmCFDUNl26GoONqT8afIIvTttPRx0NJOZBUqsji03Lf8nDbs/k5UwJ47Yw3KUVEWw9DxBvHyhDa2IavQkpb1lrKLkrLXYANskIzKqLrEbjl6lMwXmJk21Xi5ft9eoA21QT5EaKNt8VeFbEBWwQrStXrZhtV3jENL6oSUSCEqcpGXqu+LrMIYLA51lw29VGWXFDPabAR3ITGCSAhe6HjFvZBVmIS6pR5ap0Ef0aeaITey1L1e9h4s3ELoAh/AHLUaoaXW0rP6IT3iVFFB90j2smgqQAqFneJ9Y92mo39NQJJakNcMtVoUWQUoJ/tTH/f8Kp1IL1uBPDUioy1PP2Z0NbIKIMfdRqultfS1LUhVU7z3pqHGu9u9yCpARxLb8HSC9+TIIjS4OUhYa75NErpbhZnpV5VQn8vk7l9y/7E/Z/+jvOFQGXLWAbfrQj12OoFxPDa11Bossobva0MvgQlIWwdC3bKE725bmQYAjQhprffMxrZBRUheByK9hKwCzEmk9xkIpiF5HeCKFQBcmAxDQvL6EHr6AgAzw2QYD/LXh9NHQ3xKDAArk2FEyF9PeAoLAC5MhpEgiwAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFKgsgAAAFL8AyigNU846YwfAAAAAElFTkSuQmCC" alt="" />当图的最大流等于SR的和则找到了满足条件的矩阵.
另外,输出矩阵时,由于建图方法的特殊性,要用栈来倒序输出.
#include <cstdio>
#include <cstring>
const int MAXN=;//点数的最大值
const int MAXM=;//边数的最大值
const int INF=0x3fffffff; struct Node
{
int from,to,next;
int cap;
}edge[MAXM]; int tol;
int head[MAXN];
int dep[MAXN];
int gap[MAXN];//gap[x]=y :说明残留网络中dep[i]==x的个数为y int n;//n是总的点的个数,包括源点和汇点 void init()
{
tol=;
memset(head,-,sizeof(head));
} void addedge(int u,int v,int w)
{
edge[tol].from=u;
edge[tol].to=v;
edge[tol].cap=w;
edge[tol].next=head[u];
head[u]=tol++;
edge[tol].from=v;
edge[tol].to=u;
edge[tol].cap=;
edge[tol].next=head[v];
head[v]=tol++;
}
void BFS(int start,int end)
{
memset(dep,-,sizeof(dep));
memset(gap,,sizeof(gap));
gap[]=;
int que[MAXN];
int front,rear;
front=rear=;
dep[end]=;
que[rear++]=end;
while(front!=rear)
{
int u=que[front++];
if(front==MAXN)front=;
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].to;
if(dep[v]!=-)continue;
que[rear++]=v;
if(rear==MAXN)rear=;
dep[v]=dep[u]+;
++gap[dep[v]];
}
}
}
int SAP(int start,int end)
{
int res=;
BFS(start,end);
int cur[MAXN];
int S[MAXN];
int top=;
memcpy(cur,head,sizeof(head));
int u=start;
int i;
while(dep[start]<n)
{
if(u==end)
{
int temp=INF;
int inser;
for(i=;i<top;i++)
if(temp>edge[S[i]].cap)
{
temp=edge[S[i]].cap;
inser=i;
}
for(i=;i<top;i++)
{
edge[S[i]].cap-=temp;
edge[S[i]^].cap+=temp;
}
res+=temp;
top=inser;
u=edge[S[top]].from;
}
if(u!=end&&gap[dep[u]-]==)//出现断层,无增广路
break;
for(i=cur[u];i!=-;i=edge[i].next)
if(edge[i].cap!=&&dep[u]==dep[edge[i].to]+)
break;
if(i!=-)
{
cur[u]=i;
S[top++]=i;
u=edge[i].to;
}
else
{
int min=n;
for(i=head[u];i!=-;i=edge[i].next)
{
if(edge[i].cap==)continue;
if(min>dep[edge[i].to])
{
min=dep[edge[i].to];
cur[u]=i;
}
}
--gap[dep[u]];
dep[u]=min+;
++gap[dep[u]];
if(u!=start)u=edge[S[--top]].from;
}
}
return res;
}
int main()
{
int sr,sc,sum;
while(~scanf("%d",&n))
{
int N = n;
n = * n + ;
init();
int s = n - ,t = n - ;
sum = ;
for(int i = ;i < N;i++)
{
scanf("%d",&sr);
sum += sr;
addedge(s,i,sr);
}
for(int i = ;i < N;i++)
{
scanf("%d",&sc);
addedge(N + i,t,sc);
}
for(int i = ;i < N;i++)
{
for(int j = ;j < N;j++)
{
addedge(i,N + j,);
}
}
if(SAP(s,t) == sum)
{
printf("YES\n");
int stk[],sn = ;
for(int i = ;i < N;i++)
{
for(int j = head[i];edge[j].next != -;j = edge[j].next)
{
stk[sn++] = - edge[j].cap;
}
printf("%d",stk[--sn]);
while(sn > )
{
printf(" %d",stk[--sn]);
}
printf("\n");
}
}
else
printf("NO\n");
}
return ;
}
toj 1421的更多相关文章
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- [Codevs 1421]秋静叶&秋穣子(最大-最小博弈)
题目:http://codevs.cn/problem/1421/ 分析:有向树上的最大-最小博弈 先手与后手的策略不同: 先手A:让对方取得尽量少的前提下,自己取得尽量大 后手B:让自己取得尽量多的 ...
- HDU 1421 搬寝室
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- codevs 1421 秋静叶&秋穣子(树上DP+博弈)
1421 秋静叶&秋穣子 题目描述 Description 在幻想乡,秋姐妹是掌管秋天的神明,作为红叶之神的姐姐静叶和作为丰收之神的妹妹穰子.如果把红叶和果实联系在一 起,自然会想到烤红薯 ...
- TOJ 1702.A Knight's Journey
2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http:// ...
- TOJ 1139.Compromise
2015-06-03 问题简述: 大概就是输入两段文本(用小写英文字母表示),分别用#表示一段话的结束输入,输出这两个文本的最长公共子序列. 简单的LCS问题,但是输入的是一段话了,而且公共部分比较是 ...
- 优先队列运用 TOJ 4123 Job Scheduling
链接:http://acm.tju.edu.cn/toj/showp4123.html 4123. Job Scheduling Time Limit: 1.0 Seconds Memory ...
- 最小生成树 TOJ 4117 Happy tree friends
链接http://acm.tju.edu.cn/toj/showp4117.html 4117. Happy tree friends Time Limit: 1.0 Seconds Memo ...
- TOJ 4120 Zombies VS Plants
链接:http://acm.tju.edu.cn/toj/showp4120.html 4120. Zombies VS Plants Time Limit: 1.0 Seconds Memo ...
随机推荐
- iOS通讯录(纯纯的干货)
一.iOS8.0 1.访问用户通讯录的两个框架 (1)AddressBookUI.framework 提供了联系人列表界面.联系人详情界面.添加联系人界面等,一般用于选择联系人 (2)AddressB ...
- js:正则表达
一:正则表达对象方法 1:compile()方法 //编译正则表达式 实例:在字符串中全局搜索“man”,并用“person”替换,然后通过compile()方法,改变正则表达式,用person替 ...
- [App Store Connect帮助]二、 添加、编辑和删除用户(2)查看并编辑您的个人帐户
您可以在 App Store Connect 的“编辑个人资料”中查看和编辑个人信息.如果您的 Apple ID 与多个帐户相关联,您可以在您的用户帐户之间切换. 查看您的个人帐户 在任意 App S ...
- ajax 以json 的形式来传递返回参数的实例
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestWcf.aspx.c ...
- java,安卓之信息的输出
Android中实现信息的输出 java一般的打印办法为System.out.println("");J2ME也是,在ide的控制台就可以看到效果. 但是android平台,Sys ...
- Fckeditor使用方法
下载地址 http://ckeditor.com/download <?php require('../fckeditor/fckeditor.php'); ?> <html> ...
- 题解报告:hdu 1285 确定比赛名次
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 Problem Description 有N个比赛队(1<=N<=500),编号依次 ...
- 题解报告:hdu 1575 Tr A
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 Problem Description A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的 ...
- linux命令大杂烩之网络管理
在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具. 作为一款强力 ...
- PHP 在线 编辑 解析
http://www.w3schools.com/php/default.asp http://www.w3schools.com/php/showphp.asp?filename=demo_s ...