牛客国庆集训派对Day1 B. Attack on Titan
B. Attack on Titan
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
const double g2 = sqrt(2.0), INF = 1e18, eps = 1e-;
int dx[] = {, , -, , , , -, -};
int dy[] = {, -, , , -, , -, };
int nxt1[], nxt2[];
bool vis[N][N][];
double A[N][N], dis[N][N][], w[]; struct Node{
int x, y, now; double dis;
bool operator < (const Node &A) const { return dis > A.dis; }
}tmp[];
priority_queue< Node >q; int main() {
int n = read(), m = read(), C = read(), cnt = ;
for (int i = ; i <= n; ++i)
for (int j = ; j <= m; ++j) A[i][j] = read();
for (int i = -; i <= ; ++i)
for (int j = -; j <= ; ++j) {
double v = i + j * g2;
if (v >= && v <= C) w[++cnt] = v;
}
sort(w + , w + cnt + );
for (int i = ; i <= cnt; ++i) {
for (int j = i - ; ~j; --j) if (fabs(w[i] - w[j] - ) < eps) { nxt1[i] = j; break; }
for (int j = i - ; ~j; --j) if (fabs(w[i] - w[j] - g2) < eps) { nxt2[i] = j; break; }
}
for (int i = ; i <= n; ++i)
for (int j = ; j <= m; ++j)
for (int k = ; k <= cnt; ++k) dis[i][j][k] = INF;
dis[][][] = , q.push((Node){, , , });
while (!q.empty()) {
Node topp = q.top(); q.pop();
int x = topp.x, y = topp.y, now = topp.now;
if (vis[x][y][now]) continue;
if (x == n && y == m) { printf("%.10lf",dis[x][y][now]); return ; }
vis[x][y][now] = ;
int t = ;
if (w[now] + eps > ) {
for (int i = ; i < ; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (nx >= && nx <= n && ny >= && ny <= m) tmp[++t] = (Node){nx,ny,nxt1[now],};
}
}
if (w[now] + eps > g2) {
for (int i = ; i < ; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (nx >= && nx <= n && ny >= && ny <= m) tmp[++t] = (Node){nx,ny,nxt2[now],};
}
}
double d = dis[x][y][now];
if(now<cnt) tmp[++t]=(Node){x,y,now+,(w[now+]-w[now])*A[x][y]};
for (int i = ; i <= t; ++i) {
if (dis[tmp[i].x][tmp[i].y][tmp[i].now] > d + tmp[i].dis)
dis[tmp[i].x][tmp[i].y][tmp[i].now] = tmp[i].dis = d + tmp[i].dis, q.push(tmp[i]);
}
}
return ;
}
牛客国庆集训派对Day1 B. Attack on Titan的更多相关文章
- 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)
题目链接 \(Description\) 给定\(n,m,C\)及大小为\((n+1)(m+1)\)的矩阵\(c[i][j]\).平面上有\((n+1)(m+1)\)个点,从\((0,0)\)编号到\ ...
- 牛客国庆集训派对Day1 L-New Game!(最短路)
链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day1 L New Game!(堆优化dijkstra+建图)
链接:https://ac.nowcoder.com/acm/contest/201/L来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言2097 ...
- 牛客国庆集训派对Day1 Solution
A Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...
- 2019牛客国庆集训派对day1(A, B E F K)
链接:https://ac.nowcoder.com/acm/contest/1099#question A:可知符合条件的图中间肯定存在一个由1构成的矩形,找到由1构成矩形的边界,判断出现的1的数量 ...
- 牛客国庆集训派对Day1:J:Princess Principal(栈模拟求括号匹配)
题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号“白鸽队(Team White Pigeon)”的间谍.在没有任务的时候,她们会进行各种各样的训练,比如快速判断一个文档有没 ...
- 2019牛客国庆集训派对day1 K题 双向链表练习题 splay区间翻转
题目链接: 解法: 先建n颗平衡树,合并的时候将a中最右的结点翻转到根节点,b中最左的结点翻转到根节点,对合并后的根节点进行标记. #include <bits/stdc++.h> usi ...
- 2019牛客国庆集训派对day1
C 存每个值存在的位置,枚举末尾的值,再枚举前面的值,哈希二分出最长相同的,即剩下的为不同的 D \(f_{i,j,k}\)为前i位,最后一个3因子在j,次因子在k G bitset处理有多少位置符合 ...
- 牛客国庆集训派对Day6 A Birthday 费用流
牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...
随机推荐
- [SQL Server]数据库的恢复
数据库恢复是和数据库备份相对应的操作,它是将数据库备份重新加载到系统中的过程.数据库恢复可以创建备份完成时数据库中存在的相关文件,但是备份以后的所有数据库修改都将丢失. SQL Server进行数据库 ...
- 利用jTessBoxEditor工具进行Tesseract3.02.02样本训练,提高验证码识别率
1.背景 前文已经简要介绍tesseract ocr引擎的安装及基本使用,其中提到使用-l eng参数来限定语言库,可以提高识别准确率及识别效率. 本文将针对某个网站的验证码进行样本训练,形成自己的语 ...
- 批处理文件(Batch Files )
后缀是bat的文件就是批处理文件,是一种文本文件.简单的说,它的作用就是自动的连续执行多条命令,批处理文件的内容就是一条一条的命令. 新建一个批处理abc.bat,里面内容如下:@echo offec ...
- 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置(转)
安装根据这个配置的,但是opencv3.0安装不成功,后来改安2.48就可以了. http://blog.csdn.net/poem_qianmo/article/details/19809337/ ...
- centos7.4 nfs-2.3.2
http://www.linuxfromscratch.org/blfs/view/svn/basicnet/libtirpc.html 注释:安装环境centos7.4; 安装完软件成后会升级系 ...
- zabbix之自动发现Tomcat多实例(第一种:已经部署完成,后续不再添加;第二种:后续或根据需要添加Tomcat实例)
单一实例手动部署:https://www.cnblogs.com/huangyanqi/p/8522526.html 注释:参考的一位博主的博客后续做的修改,那个博主的网址找不到了!!!! 背景: 1 ...
- zabbix的日常监控-自动发现端口并监测(服务器开启的所有端口或监控指定端口)(十三)
动批量检查agent开放的端口 注:此方法给监控磁盘IO(即十二)篇过程一样: 注释:如果服务器上的应用都是固定的,不会随机产生的都可以使用自动发现端口来监控: 如果服务器会随机出现端口且每次启动程 ...
- 在windows下的hdfs客户端编写
在windows下的hdfs客户端编写 新建一个工程,右键 properties -> java build path -> libraries 和之前一样的操作,这次 new 一个 us ...
- Spfa(最短路求解)
spfa(最短路求解) 模板: #include<iostream> #include<cstdio> #include<queue> #include<cs ...
- 笔记本无密码连接wifi
用手机可以用wifi万能钥匙破解wifi,就想找电脑版的wifi万能钥匙,然并卵. 就去寻找各种办法,最后找了个巧, 用手机下载wifi万能钥匙连接,并且使用数据线连接上笔记本. 然后手机设置中找到开 ...