Gems
zoj2332:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2332
题意:这一道题的题意,我看了很久,也没有看明白,最终还是理解错了。题目的意思是有n*m种石头,有n种形状,m种颜色。一个人对于每一种形状有一定的容忍度,另外一个人对于每一种颜色有一定容忍度,然后问你能把这些石头分给这两个人,使得每个人能够满意。
题解:每一种石头作为一个点,与源点连边,边的容量就是石头的数量,然后每一行作为一个点,对应每一种形状的,容量是INF,然后是每一列一个点,与宝石连接,INF,然后每个行与BF连接,就是每一种形状的容忍度,每一列与GF连接,就是每一种颜色的容忍度,然后BF,GF与汇点连接,INF。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#define INF 100000000
using namespace std;
const int N=;
const int M=;
struct Node{
int v;
int f;
int next;
}edge[M];
int n,m,u,v,cnt,sx,ex;
int head[N],pre[N];
int mp[N][N],a1[N],a2[N];
void init(){
cnt=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w){
edge[cnt].v=v;
edge[cnt].f=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].f=;
edge[cnt].v=u;
edge[cnt].next=head[v];
head[v]=cnt++;
}
bool BFS(){
memset(pre,,sizeof(pre));
pre[sx]=;
queue<int>Q;
Q.push(sx);
while(!Q.empty()){
int d=Q.front();
Q.pop();
for(int i=head[d];i!=-;i=edge[i].next ){
if(edge[i].f&&!pre[edge[i].v]){
pre[edge[i].v]=pre[d]+;
Q.push(edge[i].v);
}
}
}
return pre[ex]>;
}
int dinic(int flow,int ps){
int f=flow;
if(ps==ex)return f;
for(int i=head[ps];i!=-;i=edge[i].next){
if(edge[i].f&&pre[edge[i].v]==pre[ps]+){
int a=edge[i].f;
int t=dinic(min(a,flow),edge[i].v);
edge[i].f-=t;
edge[i^].f+=t;
flow-=t;
if(flow<=)break;
} }
if(f-flow<=)pre[ps]=-;
return f-flow;
}
int solve(){
int sum=;
while(BFS())
sum+=dinic(INF,sx);
return sum;
}
int main() {
int T,k,temp,sum,d,t1,t2,t3,t4,tt=;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
init();sum=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%d",&temp);
sum+=temp;
add(,(i-)*m+j,temp);
} scanf("%d",&d);
for(int i=;i<=d;i++){
scanf("%d%d%d%d",&t1,&t2,&t3,&t4);
t2++;t4++;
add(t1*m+t2,t3*m+t4,INF);
add(t3*m+t4,t1*m+t2,INF);
}
for(int i=;i<=n;i++){
scanf("%d",&temp);
for(int j=;j<=m;j++){
add((i-)*m+j,n*m+i,INF);
}
add(n*m+i,n*m+m+n+,temp);
}
for(int i=;i<=m;i++){
scanf("%d",&temp);
for(int j=;j<=n;j++){
add((j-)*m+i,n*m+n+i,INF);
}
add(n*m+n+i,n*m+m+n+,temp);
}
add(n*m+n+m+,n*m+n+m+,INF);
add(n*m+n+m+,n*m+n+m+,INF);
sx=,ex=n*m+n+m+;
int td=solve();
if(td==sum)printf("Yes\n");
else
printf("No\n");
}
return ;
}
Gems的更多相关文章
- Unable to download data from http://ruby.taobao.org/ & don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
安装cocoapods,记录两个问题! 1.镜像已经替换成了 http://ruby.taobao.org/, 还是不能不能安装cocoapods, 报错:Unable to download dat ...
- ACM: Racing Gems - 最长递增序列
Racing Gems You are playing a racing game. Your character starts at the x axis (y = 0) and procee ...
- UVALive - 7374 Racing Gems 二维非递减子序列
题目链接: http://acm.hust.edu.cn/vjudge/problem/356795 Racing Gems Time Limit: 3000MS 问题描述 You are playi ...
- uva 10274 Fans and Gems(隐式图搜索+模拟)
Fans and Gems Input: Standard Input Output: Standard Output Tomy's fond of a game called 'Fans and G ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- ruby gem源更换国内源gems.ruby-china.org数据源
gem sources -l gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ 更新缓存 ge ...
- hdu 6199 沈阳网络赛---gems gems gems(DP)
题目链接 Problem Description Now there are n gems, each of which has its own value. Alice and Bob play a ...
- hdu 4778 Gems Fight! 状态压缩DP
Gems Fight! Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)T ...
- Error fetching https://gems.ruby-china.org/: bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz) 报错解决办法
执行换源操作 gem source -a https://gems.ruby-china.org/ 时报错: Error fetching https://gems.ruby-china.org/: ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- mysql中enum的用法
字段 类型 长度/值*1 整理 属性 Null 默认2 额外 注释 enum 说明:enum类型的字段,若长度值写长度1/2,报错 (1) 数据长度为1,则为0,1,2… (2) ...
- (转载)OSI七层参考模型和TCP/IP四层参考模型
Mallory 网络模型概念浅析 网络模型一般是指OSI七层参考模型和TCP/IP四层参考模型. #只是一种设计==模型# Open System Interconnect的缩写,意为开放式系统互 ...
- SVN/GIT源代码泄露
造成SVN源代码漏洞的主要原因是管理员操作不规范.在使用SVN管理本地代码过程中,会自动生成一个名为.svn的隐藏文件夹,其中包含重要的源代码信息.但一些网站管理员在发布代码时,不愿意使用‘导出’功能 ...
- 关于Clone 的方法使用
package cn.hncu.day7.clone.v1;//克隆的套路:// 第1步:重写User类的clone()方法,以供外面调用.因为外面的类无法直接调用User类父类中的clone()方法 ...
- Java基础知识强化之网络编程笔记08:TCP之客户端键盘录入服务器控制台输出
1. 客户端: package cn.itcast_08; import java.io.BufferedReader; import java.io.BufferedWriter; import j ...
- php 表单的活用
一般表单都是用过POST 方式对数据进行隐秘的传输用, 可以偶尔你也会发现这样的用法,表单不止能够进行隐秘的传输.还能够进行URL的传输,并且是同时进行的 提交页面,在action 后面加了URL后缀 ...
- 在解决方案中添加Layout,Image文件夹
在解决方案中添加文件夹如Layout,Image,可以使用映射的方式(右键该解决方案,添加对Layout的映射),这样IIS的地址和该文件夹就绑定了:拖该文件夹中的 文件时,显示的就是该文件在IIS中 ...
- 字符编码笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian
转载:http://witmax.cn/character-encoding-notes.html 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问 ...
- (一)问候Struts2
第一节:Struts2 简介 主页:http://struts.apache.org/在用户请求和模块化处理方面以及页面的展现这块,Struts2 发挥的屌炸天作用:相对于传统的Jsp+Servlet ...
- 利用SpringMVC参数绑定实现动态插入数据
javabean代码:public class User { private String firstName; private String lastName; public String getF ...