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 ...
随机推荐
- (转载)OSI七层参考模型和TCP/IP四层参考模型
Mallory 网络模型概念浅析 网络模型一般是指OSI七层参考模型和TCP/IP四层参考模型. #只是一种设计==模型# Open System Interconnect的缩写,意为开放式系统互 ...
- j2ee学习笔记URLEncoder.encode(String , enc)处理特殊字符
从页面上传递数据时,特殊字符对于超链接会自动进行解码 : 其他方式需要手动进行解码.
- InnoDB MyISAM区别及优化(摘录)
InnoDB 是 MySQL 上第一个提供外键约束的引擎,除了提供事务处理外,InnoDB 还支持行锁,提供和 Oracle 一样的一致性的不加锁读取,能增加并发读的用户数量并提高性能,不会增加锁的数 ...
- Android(java)学习笔记181:利用Service在后台播放背景音乐
1.在android应用程序里,有一种没有UI的类(android.app.Service)——Service.简单来说,Service是一个 background process(背景程序),通过背 ...
- php 5.3起弃用session_register
最近下了dedecms V5.7时,在登陆后台时,用户名和密码也没错,就是跳转不走,进不了后台管理页面,追踪了好久才发现根目录/include/userlogin.class.php中289行左右的位 ...
- DEDE自带的采集功能,标题太短的解决方法
DEDE自带的采集功能,标题太短获取不全的解决方法搜索了好多之后,终于还是在dede的官方论坛找到了答案.增加采集标题长度:255 目的:原标题长度太小,影响文件采集⑴修改系统参数设置(文档标题最大 ...
- 类似与三元表达式的 json 读取值
需要先在项目中添加 json的dll json 序列里面的key在item.feeType里面必须存在 否则会报 未将对象引用到实例 myDr["feeType"] = Newto ...
- GPS定位,经纬度附近地点查询–C#实现方法
目前的工作是需要手机查找附近N米以内的商户,功能如下图 数据库中记录了商家在百度标注的经纬度(如:116.412007, 39.947545), 最初想法 以圆心点为中心点,对半径做循环,半径每增加 ...
- Wi-Fi无线网络下行速度超级慢 (5kb/s)之解决方案
转载:http://www.iplaysoft.com/wifi-slow-solution.html 作者:X-Force 转载原因:该文分类提出了多种解决方案,并详述其原因.简洁清晰,可作为参考方 ...
- 在Android上模拟登录广工正方教务系统查询成绩
这是在博客园里开博以来写的第一篇博客. 因为之前看过很多人都有发过关于模拟登录正方软件获取数据的文章,自己觉得挺好玩的便也去动手一做,开始还以为挺难的,但实际做起来还蛮简单的,当然其中还有些小插曲. ...