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的更多相关文章

  1. 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)

    题目链接 \(Description\) 给定\(n,m,C\)及大小为\((n+1)(m+1)\)的矩阵\(c[i][j]\).平面上有\((n+1)(m+1)\)个点,从\((0,0)\)编号到\ ...

  2. 牛客国庆集训派对Day1 L-New Game!(最短路)

    链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  3. 牛客国庆集训派对Day1 L New Game!(堆优化dijkstra+建图)

    链接:https://ac.nowcoder.com/acm/contest/201/L来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言2097 ...

  4. 牛客国庆集训派对Day1 Solution

    A    Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...

  5. 2019牛客国庆集训派对day1(A, B E F K)

    链接:https://ac.nowcoder.com/acm/contest/1099#question A:可知符合条件的图中间肯定存在一个由1构成的矩形,找到由1构成矩形的边界,判断出现的1的数量 ...

  6. 牛客国庆集训派对Day1:J:Princess Principal(栈模拟求括号匹配)

    题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号“白鸽队(Team White Pigeon)”的间谍.在没有任务的时候,她们会进行各种各样的训练,比如快速判断一个文档有没 ...

  7. 2019牛客国庆集训派对day1 K题 双向链表练习题 splay区间翻转

    题目链接: 解法: 先建n颗平衡树,合并的时候将a中最右的结点翻转到根节点,b中最左的结点翻转到根节点,对合并后的根节点进行标记. #include <bits/stdc++.h> usi ...

  8. 2019牛客国庆集训派对day1

    C 存每个值存在的位置,枚举末尾的值,再枚举前面的值,哈希二分出最长相同的,即剩下的为不同的 D \(f_{i,j,k}\)为前i位,最后一个3因子在j,次因子在k G bitset处理有多少位置符合 ...

  9. 牛客国庆集训派对Day6 A Birthday 费用流

    牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...

随机推荐

  1. 《SQL Server 2008从入门到精通》--20180703

    SELECT操作多表数据 关于连接的问题,在<SQL必知必会>学习笔记中已经讲到过,但是没有掌握完全,所以再学一下. JOIN连接 首先我们先来看一下最简单的连接.Products表和Ve ...

  2. GBK与UTF-8编码错误转换后,无法再正确恢复

    字符集错误转换导致的问题 UTF-8格式编码的字节流,按GBK字符集转换为字符串,会出现乱码,这很正常.但将其重新转为字节流,再用UTF-8字符集转为字符串,还是乱码.这就让我产生了疑惑,虽然使用错误 ...

  3. MySQL: OPTIMIZE TABLE: Table does not support optimize, doing recreate + analyze instead

    show create table history;-------------------------- CREATE TABLE `foo` (  `itemid` bigint(20) unsig ...

  4. Build path entry is missing: config 引起的 The project: configwhich is referenced by the classpath, does not exist.

    运行Junit的时候报错, The project: XXXX which is referenced by the classpath, does not exist. 在Java Build Pa ...

  5. September 24th 2017 Week 39th Sunday

    To live is the rarest thing in the world. Most people exist. That is all. 生活是世间最罕见的事情:生存,却是世间最常见的事情: ...

  6. 使用github客户端上传文件(瓜皮教程)

    因为栋哥的课才接触道github这个东西,离第一次接触大概有一年左右了吧,记得不是太清楚了,但是,直到前几天前我还是不知道如何配置,利用git上传文件,之前也是叫同学帮忙弄得,但是这次软工实践要频繁用 ...

  7. 【转】Json判断是否存在某个属性和遍历各个属性和值

    var field='uid'; var jsonObj={uid:'001'}; 一. jsonObj[field] != undefined //注意:如果field值正好是undefined那就 ...

  8. 使用 CSS 根据兄弟元素的个数来调整样式

    在某些场景下,我们需要根据兄弟元素的总数来为它们设置样式.最常见的场景就是,当一个列表不断延长时,通过隐藏控件或压缩控件等方式来节省屏幕空间,以此提升用户体验. 为保证一屏内容能展示更多的内容,需要将 ...

  9. 【洛谷】【线段树+位运算】P2574 XOR的艺术

    [题目描述:] AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为n的01串. 2. 给定一个范围[ ...

  10. TreeMap实现原理及源码分析之JDK8

    转载 Java 集合系列12之 TreeMap详细介绍(源码解析)和使用示例 一.TreeMap 简单介绍 什么是Map? 在数组中我们通过数组下标来对数组内容进行索引的,而在Map中我们通过对象来对 ...