牛客国庆集训派对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 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...
随机推荐
- UITableVIew与UICollectionView带动画删除cell时崩溃的处理
UITableVIew与UICollectionView带动画删除cell时崩溃的处理 -会崩溃的原因是因为没有处理好数据源与cell之间的协调关系- 效果: tableView的源码: ModelC ...
- 限定pan手势只能在圆内移动view
限定pan手势只能在圆内移动view 效果: 虽然看起来很简单,但实现原理还是稍微有点复杂-_-!! 核心的地方,就是需要计算pan手势的点与指定点的距离,不能超过这个距离,超过了就让动画还原,很容易 ...
- wordpress利用rsync同步备份
我搭建的wordpress服务器现在使用的系统是opensuse, 服务器上面已做脚本和计划任务将wordpress使用的数据库与web目录每天压缩备份放到 /data/backup目录下 opera ...
- jquery ajax跨域解决
双十一开发了一个抽奖API,最近上线了,各个事业部的大神们需要前台页面,异步调用我的抽奖API,要我提供js. js 提供之后发现不对,跨域了.之前也碰到过跨域的问题,研究过这个问题,三种方法解决. ...
- DNS Brand
1) You must add glue records (child nameservers) to your-domain.com from your domain's registrar con ...
- C# 词法分析器(一)词法分析介绍
系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 虽然文章的标题是词法分析,但首先还是要从编译原理说开 ...
- swift的enum模式—对Alamofire入口的解析--数据结构与操作结合的模式
swift的枚举模式是数据结构与操作结合的模式 1.enum本质是一个类型,可以定义变量: 它定义的变量可以用到其它变量用的的任何地方:函数的输入.输出.成员变量.临时变量等: 这个变量还可以带有附加 ...
- 【openjudge】【字符串+模拟】1777:文件结构“图”
[题目传送门:]戳 [描述:] 在计算机上看到文件系统的结构通常很有用.Microsoft Windows上面的"explorer"程序就是这样的一个例子.但是在有图形界面之前,没 ...
- Day4 数组
双重for循环 外循环控制行,内循环控制列. //乘法表 ; i <= ; i++) { ; j <= i ;j++) { System.out.print(j+"*" ...
- Django 连接Mysql异常处理
启动manage.py提示 连接数据库异常 django.db.utils.OperationalError: (2003, "Can't connect to MySQL server o ...