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 ...
随机推荐
- Freemarker学习中遇到的问题
在网上找到了尚学堂的视频,同时有书和源码等资料.但是在跟着练习的过程中,代码运行报了错: 2015-7-20 22:26:40 freemarker.log.JDK14LoggerFactory$JD ...
- HDU2017JAVA
字符串统计 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 【Android】isEmpty()
对字符串进行非空判断,可以一次性进行两种空值的判断.当传入的字符串等于null或者等于空字符串的时候这个方法都会返回true,从而不需要单独去判断这两种空值,再利用逻辑运算符连接起来.
- windows向ubuntu过渡之常用软件安装
好久没有写博客了,介于最近上操作系统实验课,好多同学装上了ubuntu,网上的教程比较杂乱,下面我就总结分享一些安装完ubuntu要安装的常用软件,会持续更新... 1.搜狗拼音安装 (1)在安装输入 ...
- Ubuntu安装sar出错Please check if data collecting is enabled in /etc/default/sysstat
1.安装sysstat apt-get install sysstat 2.安装后无法使用: Cannot open /var/log/sysstat/sa02: No such file or di ...
- C#面向对象(二)
一:抽象方法 1. 在面向对象编程语言中抽象方法指一些只有方法声明,而没有具体方法体的方法.抽象方法一般存在于抽象类或接口中. 在一些父类中,某些行为不是非常明确,因此无法用代码来具体实现,但是类还必 ...
- 29、Jquery Ajax
Ajax Asynchronsous Javascript and XML(异步Javascript和XML). Ajax 是一种无需重新加载整个页面的情况下,更新局部页面的技术. 不是指一种单一的技 ...
- 验证jquery.validate.js
<pre>jquery.validate.js使用之自定义表单验证规则,下面列出了一些常用的验证法规则 jquery.validate.js演示查看 <a href="ht ...
- shit-------------mysql没有full join 语句
弄了好久,结果发现-------- 因为mysql没有full join这个东西 你只能写成 sleect * from A left join B on A.id=B.idunionselect * ...
- 在解决方案中添加Layout,Image文件夹
在解决方案中添加文件夹如Layout,Image,可以使用映射的方式(右键该解决方案,添加对Layout的映射),这样IIS的地址和该文件夹就绑定了:拖该文件夹中的 文件时,显示的就是该文件在IIS中 ...