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. FileStream对文本进行读写操作

    class FileHelper { /// <summary> /// 检验文件路径是否合法 /// </summary> /// <param name=" ...

  2. mongodb/python3.6/mysql的安装

    1 下载与解压 在官网下载mongodb安装包 tar -zxvf mongodb-linux-x86_64-ubuntu1604-3.4.0.tgz 2 移动安装文件 sudo mv mongodb ...

  3. Swift-EasingAnimation

    Swift-EasingAnimation 效果 http://gizma.com/easing/ 源码 https://github.com/YouXianMing/UI-Component-Col ...

  4. 产生渐变色的view

    产生渐变色的view 效果 源码 https://github.com/YouXianMing/UI-Component-Collection // // GradientColorView.h // ...

  5. 用一个变量表示 ----------"序号,名称,价格"

     goods = [{"name": "电脑", "price": 1999},          {"name": & ...

  6. SICP 习题 (1.34)解题总结

    SICP 习题 1.34的题目比較特别一点.对于没有接触过高阶函数的同学们来说是个非常好的学习机会. 题目是这种,假设我们定义以下的过程: (define (f g)   (g 2)) 那么就有: ( ...

  7. BZOJ4756:[USACO]Promotion Counting(线段树合并)

    Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对于每个奶牛来说,它的子树中有几个能力值比它大的. Input n,表示有几只奶牛 n<=10 ...

  8. Hive学习之路 (十五)Hive分析窗口函数(三) CUME_DIST和PERCENT_RANK

    这两个序列分析函数不是很常用,这里也练习一下. 数据准备 数据格式 cookie3.txt d1,user1, d1,user2, d1,user3, d2,user4, d2,user5, 创建表 ...

  9. Python之Flask框架使用

    Flask和Django.Bottle号称Python中的强大又简单的Web框架. Flask是一个使用Python编写的轻量级Web应用框架.基于Werkzeug WSGI工具箱和Jinja2 模板 ...

  10. 关于vmware workstation10常见问题

    简单的说明:win7和win10的解决办法都是这个,都可以用这个解决. 这是一个共性的问题. 出现这个问题的原因是: a.要么是系统更新没有及时正确的关闭虚拟机导致的; b.没有及时将虚拟机手动关闭再 ...