题解:

二分+宽搜+KM

显然答案不能太大

然后二分一下

代码:

#include<bits/stdc++.h>
const int N=,M=;
using namespace std;
const int dx[]={-,,,},dy[]={,,-,};
int m,n,cnt,pt,tot,c[N][N],d[N][N],x,y,t,path[N],bo[N],inq[N][N],mp[N][N];
struct node{int x,y;}a[N],b[N],h[N+];
void bfs(int sx,int sy,int p)
{
memset(d,0x3f,sizeof(d));
d[sx][sy]=;
int i,t,head=,tail=;
node u,v;
h[].x=sx;h[].y=sy;
memset(inq,,sizeof(inq));
while (head!=tail)
{
head=head%M+;u=h[head];inq[u.x][u.y]=;
for (int i=;i<;i++)
{
v.x=u.x+dx[i];v.y=u.y+dy[i];
if (v.x<=||v.x>m||v.y<=||v.y>n) continue;
if (p^(d[u.x][u.y]&))
if (c[v.x][v.y]<=c[u.x][u.y]) t=;else t=;
else
if (c[v.x][v.y]>=c[u.x][u.y]) t=;else t=;
if (d[u.x][u.y]+t<d[v.x][v.y])
{
d[v.x][v.y]=d[u.x][u.y]+t;
if (!inq[v.x][v.y]){inq[v.x][v.y]=;tail=tail%M+;h[tail]=v;}
}
}
}
}
int dfs(int x,int lim)
{
for (int i=;i<=tot;i++)
if (bo[i]&&mp[x][i]<=lim)
{
bo[i]=;
if (!path[i]||dfs(path[i],lim))
{
path[i]=x;
return ;
}
}
return ;
}
int pd(int x)
{
int tmp=;
memset(path,,sizeof(path));
for (int i=;i<=(cnt<<);i++)
{
memset(bo,,sizeof(bo));
tmp+=(dfs(i,x));
}
return tmp+x>=(cnt<<);
}
int main()
{
scanf("%d%d%d%d",&m,&n,&cnt,&pt);
for (int i=;i<=(cnt<<|);i++)scanf("%d%d",&a[i].x,&a[i].y);
for (int i=;i<=pt;i++)
{
scanf("%d%d%d",&x,&y,&t);
while (t--){b[++tot].x=x;b[tot].y=y;}
}
for (int i=;i<=m;i++)
for (int j=;j<=n;j++)scanf("%d",&c[i][j]);
for (int i=;i<=(cnt<<);i++)
{
if (i<=cnt) bfs(a[i].x,a[i].y,); else bfs(a[i].x,a[i].y,);
for (int j=;j<=tot;j++) mp[i][j]=d[b[j].x][b[j].y];
}
int l=,r=cnt<<;
while (l<r)
{
int mid=(l+r)>>;
if (pd(mid)) r=mid;
else l=mid+;
}
printf("%d\n",l);
return ;
}

bzoj2547的更多相关文章

  1. BZOJ2547 CTSC2002玩具兵(最短路径+二分答案+最大流)

    先不考虑只有一个显得有些特殊的天兵. 可以发现超能力的作用实质上是使兵更换职业.每一个兵到达某个位置最少需要更换职业的次数是彼此独立的,因为如果需要某两人互换职业可以使他们各自以当前职业到达需要到的地 ...

  2. bzoj2547: [Ctsc2002]玩具兵

    划了一天水,其实我还是有点愧疚的. 传送门 其实是水题,然而我真是太蠢了... 首先不考虑天兵,其他兵要到一个点去一定是通过它-另一种兵-它……这样多次交换的,并且交换对象是无所谓的,和它换的兵最终会 ...

  3. [bzoj2547]玩具兵<Spfa+二分+匈牙利算法>

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2547 挺有意思的一道题,这道题可以划分成几个小题....... 题目大意: 三个兵种在一个 ...

随机推荐

  1. hust1010 The Minimum Length

    地址:http://acm.hust.edu.cn/problem/show/1010 题目: 1010 - The Minimum Length Time Limit: 1s Memory Limi ...

  2. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  3. 【转】深入浅出UML类图

    转自:http://www.cppblog.com/API/archive/2013/07/04/201506.html 在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin ...

  4. JS正则表达式从入门到入土(9)—— test方法以及它的那些坑

    test方法 test方法介绍 RegExp.prototype.test(str) test方法用于测试字符串参数中是否存在匹配正则表达式模式的字符串 test方法的使用 let reg = /\w ...

  5. mongodb 索引的创建

    mongodb 创建常用的创建索引的有 signle Field Indexes Compound multikey,创建索引就是按照索引字段把documnet 进行排序,索引只存储了document ...

  6. How To Use Coordinates To Extract Sequences In Fasta File

    [1] bedtools (https://github.com/arq5x/bedtools2) here is also bedtools (https://github.com/arq5x/be ...

  7. Hive中的数据倾斜

    Hive中的数据倾斜 hive 1. 什么是数据倾斜 mapreduce中,相同key的value都给一个reduce,如果个别key的数据过多,而其他key的较少,就会出现数据倾斜.通俗的说,就是我 ...

  8. Android Device Monitor 文件管理使用的常见问题

    本文参照博客:http://blog.csdn.net/aurorayqz/article/details/65705300.以下是我的实际操作. 1.使用Android Device Monitor ...

  9. TCP_DB_中间件_数据打包格式

    ZC: 这里约定的是,C和S之间 传输的TCP数据包的格式 1.TCP数据包 打包格式 1.1.TCP包长度(int32) + TCP包序号(int32) + TCP包类型(int32) + TCP包 ...

  10. thinkphp getField("xxxxx", true); 得到一个字段所有值组成的的数组

    很多时候我们只需要一张表里某个字段的值,组成的数组 $Channel = D('channel');$channelList = $Channel->order('user_name')-> ...