BZOJ 1556 墓地秘密
2333333333333333333333333333333333333333333333
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人辣鸡出题人
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<queue>
- #include<algorithm>
- #define inf 1000000007
- using namespace std;
- int n,m,t,wh[][],dis[][],x[],y[],tab[][][][],pre[][],fro[][][][],f[(<<)+][][];
- int dx[]={,-,,,},dy[]={,,,,-};
- bool map[][],vis[][];
- char s[];
- queue <int> q;
- void reset()
- {
- for (int i=;i<=n;i++)
- for (int j=;j<=m;j++)
- dis[i][j]=inf;
- while (!q.empty()) q.pop();
- memset(vis,false,sizeof(vis));
- }
- bool judge(int x,int y)
- {
- if ((x>=) && (x<=n) && (y>=) && (y<=m) && (!map[x][y]))
- return true;
- return false;
- }
- void spfa(int pos,int dir)
- {
- memset(pre,,sizeof(pre));
- if (!judge(x[pos]+dx[dir],y[pos]+dy[dir])) return;
- dis[x[pos]+dx[dir]][y[pos]+dy[dir]]=;vis[x[pos]+dx[dir]][y[pos]+dy[dir]]=true;
- q.push(x[pos]+dx[dir]);q.push(y[pos]+dy[dir]);
- while (!q.empty())
- {
- int hx,hy;
- hx=q.front();q.pop();hy=q.front();q.pop();
- int p=;
- while (judge(hx-p,hy))
- {
- if ((dis[hx-p][hy]>dis[hx][hy]+) || ((dis[hx-p][hy]==dis[hx][hy]+) && (wh[hx-p][hy]==)))
- {
- dis[hx-p][hy]=dis[hx][hy]+;
- pre[hx-p][hy]=;
- if (!vis[hx-p][hy])
- {
- vis[hx-p][hy]=true;
- q.push(hx-p);q.push(hy);
- }
- }
- p++;
- }
- p=;
- while (judge(hx+p,hy))
- {
- if ((dis[hx+p][hy]>dis[hx][hy]+) || ((dis[hx+p][hy]==dis[hx][hy]+) && (wh[hx+p][hy]==)))
- {
- dis[hx+p][hy]=dis[hx][hy]+;
- pre[hx+p][hy]=;
- if (!vis[hx+p][hy])
- {
- vis[hx+p][hy]=true;
- q.push(hx+p);q.push(hy);
- }
- }
- p++;
- }
- p=;
- while (judge(hx,hy-p))
- {
- if ((dis[hx][hy-p]>dis[hx][hy]+) || ((dis[hx][hy-p]==dis[hx][hy]+) && (wh[hx][hy-p]==)))
- {
- dis[hx][hy-p]=dis[hx][hy]+;
- pre[hx][hy-p]=;
- if (!vis[hx][hy-p])
- {
- vis[hx][hy-p]=true;
- q.push(hx);q.push(hy-p);
- }
- }
- p++;
- }
- p=;
- while (judge(hx,hy+p))
- {
- if ((dis[hx][hy+p]>dis[hx][hy]+) || ((dis[hx][hy+p]==dis[hx][hy]+) && (wh[hx][hy+p]==)))
- {
- dis[hx][hy+p]=dis[hx][hy]+;
- pre[hx][hy+p]=;
- if (!vis[hx][hy+p])
- {
- vis[hx][hy+p]=true;
- q.push(hx);q.push(hy+p);
- }
- }
- p++;
- }
- vis[hx][hy]=false;
- }
- }
- void get_tab(int pos,int dir)
- {
- for (int i=;i<=t+;i++)
- for (int j=;j<=;j++)
- {
- if (judge(x[i]+dx[j],y[i]+dy[j]))
- {
- tab[pos][dir][i][j]=dis[x[i]+dx[j]][y[i]+dy[j]];
- fro[pos][dir][i][j]=pre[x[i]+dx[j]][y[i]+dy[j]];
- }
- }
- }
- int main()
- {
- //freopen("secret.in","r",stdin);
- //freopen("secret.out","w",stdout);
- memset(map,false,sizeof(map));
- scanf("%d%d%d",&n,&m,&t);
- for (int i=;i<=n;i++)
- {
- scanf("\n%s",s);
- for (int j=;j<m;j++)
- if (s[j]=='#') map[i][j+]=true;
- }
- for (int i=;i<=t;i++)
- {
- scanf("%d%d",&x[i],&y[i]);
- map[x[i]][y[i]]=true;
- }
- for (int i=;i<=t;i++)
- {
- for (int j=;j<=;j++)
- {
- if (judge(x[i]+dx[j],y[i]+dy[j]))
- wh[x[i]+dx[j]][y[i]+dy[j]]=j;
- }
- }
- scanf("%d%d",&x[t+],&y[t+]);
- for (int i=;i<=t+;i++)
- for (int j=;j<=;j++)
- for (int k=;k<=t;k++)
- for (int l=;l<=;l++)
- tab[i][j][k][l]=inf;
- for (int i=;i<=t;i++)
- {
- for (int j=;j<=;j++)
- {
- reset();
- spfa(i,j);
- get_tab(i,j);
- }
- }
- reset();
- spfa(t+,);
- for (int i=;i<=t+;i++)
- for (int j=;j<=;j++)
- {
- if (judge(x[i]+dx[j],y[i]+dy[j]))
- {
- tab[t+][][i][j]=dis[x[i]+dx[j]][y[i]+dy[j]];
- fro[t+][][i][j]=pre[x[i]+dx[j]][y[i]+dy[j]];
- }
- }
- int top=(<<t)-;
- for (int s=;s<=top;s++)
- for (int i=;i<=t;i++)
- for (int j=;j<=;j++)
- f[s][i][j]=inf;
- for (int i=;i<=t;i++)
- for (int j=;j<=;j++)
- {
- if (fro[t+][][i][j]!=j)
- f[<<(i-)][i][j]=tab[t+][][i][j]+;
- else f[<<(i-)][i][j]=tab[t+][][i][j];
- }
- for (int ss=;ss<=top;ss++)
- {
- for (int i=;i<=t;i++)
- {
- if (ss&(<<(i-)))
- {
- for (int j=;j<=t;j++)
- {
- if (ss&(<<(j-))) continue;
- for (int k=;k<=;k++)
- for (int l=;l<=;l++)
- {
- if (tab[i][k][j][l]==inf) continue;
- if (fro[i][k][j][l]!=l)
- f[ss|<<(j-)][j][l]=min(f[ss|<<(j-)][j][l],f[ss][i][k]+tab[i][k][j][l]+);
- else f[ss|<<(j-)][j][l]=min(f[ss|<<(j-)][j][l],f[ss][i][k]+tab[i][k][j][l]);
- }
- }
- }
- }
- }
- int ans=inf;
- for (int i=;i<=t;i++)
- for (int j=;j<=;j++)
- ans=min(ans,f[top][i][j]);
- printf("%d\n",ans);
- return ;
- }
BZOJ 1556 墓地秘密的更多相关文章
- bzoj 1556 墓地秘密 —— 状压DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1556 预处理出两个障碍四个方向之间的距离(转弯次数),就可以状压DP了: 但预处理很麻烦.. ...
- bzoj 1556: 墓地秘密【状压dp+spfa】
显然是状压,显然不可能把所有格子压起来 仔细观察发现只有机关周围的四个格子有用以及起点,所以我们用spfa处理出这些格子两两之间的距离(注意细节--这里写挂了好几次),然后设f[s][i]为碰完的机关 ...
- BZOJ1556 墓地秘密
题意 费尽周折,终于将众将士的残骸运送到了KD军事基地地底层的大型墓地入口.KD的伙伴和战友们都参加了这次重大的送葬仪式.右边是一扇敞开的大门,进去便是墓地了,左边是一堵凹进去的墙,没有什么特别的地方 ...
- 洛谷 2922 BZOJ 1590 [USACO08DEC]秘密消息Secret Message
[题意概述] 给出n个01串组成的字典和m个询问,每次询问某个01串和多少个字典中的串有相同的前缀.(前缀长度是两串中较小的部分) [题解] 直接上Trie树即可.树上每个节点记录两个信息:这个节点有 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 刷题总结(持续更新)
本篇博客按照题号排序(带*为推荐题目) 1008 [HNOI2008]越狱 很经典的题了..龟速乘,龟速幂裸题,, 1010 [HNOI2008]玩具装箱toy* 斜率优化 基本算是裸题. 1012 ...
- bzoj1556 (DP)
bzoj 1556 点这里打开题目 题目是求 a^2 求和: 原问题可以转化为:两个人在玩这个东西,问这两个人弄出来的序列相同的有多少种情况,操作方式不同即为一种不同的情况. 就这个问题,参考大佬的D ...
- bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息 Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共 ...
- 【BZOJ】1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1643 这题和完全背包十分相似, 但是不能用1维做........原因貌似是不能确定块数(还是有0的面 ...
随机推荐
- GridControl Find/Clear 添加图标
public static void ControlFind(GridControl grid) { FindControl fControl = null; foreach (Control ite ...
- ExtJS之Ext.getDom
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- arcgis地图操作的资料URL,以供以后查阅
更改Arcgis Web应用程序的端口号8399: http://help.arcgis.com/zh-cn/arcgisserver/10.0/help/arcgis_server_java_hel ...
- 23种设计模式学习一(单列模式)singleton
单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...
- 【uva753/poj1087/hdu1526-A Plug for UNIX】最大流
题意:给定n个插座,m个插头,k个转换器(x,y),转换器可以让插头x转成插头y.问最少有多少个插头被剩下. 题解: 最大流或者二分图匹配.然而我不知道怎么打二分图匹配..打了最大流.这题字符串比较坑 ...
- JavaWeb项目开发案例精粹-第6章报价管理系统-04Service层
1. package com.sanqing.service; import com.sanqing.dao.DAO; import com.sanqing.po.Customer; /** * 客户 ...
- 扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法
扩展 delphi 泛型 以实现类似lambda功能 , C#中的any count first last 等扩展方法 在C#中对泛型的扩展,输入参数是泛型本身的内容,返回值则是bool.基于这一点, ...
- USACO Section 3.1: Agri-Net
minimal spanning tree的经典题 /* ID: yingzho1 LANG: C++ TASK: agrinet */ #include <iostream> #incl ...
- jenkins的搭建和使用
Jenkins 是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从繁杂的集成中解脱出来,专注于更为重要的业务逻辑实现上.同时 Jenkins 能实施监控集成中存在的错误,提供详细的日志文件和 ...
- 由反汇编C程序来理解计算机是如何工作的
C语言代码 int g(int x) { return x + 109; } int f(int x) { return g(x); } int main() { return f(122) + 3; ...