话说hzwer你在坑爹?、、、

我按照你的建图交了上去,发现WA。

开始检查= =。。。过了好久,突然觉得画风不对。。。hzwer您建图错了啊!!!

后来看了看zky的终于知道了怎么回事>_<

 /**************************************************************
Problem: 2259
User: rausen
Language: C++
Result: Accepted
Time:3220 ms
Memory:52884 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue> using namespace std;
typedef long long ll;
const int N = ;
const int M = ; int n, tot;
int dis[N], first[N];
bool vis[N], pre[N], nxt[N]; struct edges {
int next, to, v;
edges() {}
edges(int _n, int _t, int _v) : next(_n), to(_t), v(_v) {}
} e[M]; struct heap_node {
int v, to;
heap_node() {}
heap_node(int _v, int _to) : v(_v), to(_to) {} inline bool operator < (const heap_node &b) const {
return v > b.v;
}
}; priority_queue <heap_node> h; inline int read() {
int x = ;
char ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
} void add_edge(int x, int y, int z) {
e[++tot] = edges(first[x], y, z);
first[x] = tot;
} inline void add_to_heap(const int p) {
for (int x = first[p]; x; x = e[x].next)
if (dis[e[x].to] == -)
h.push(heap_node(e[x].v + dis[p], e[x].to));
} void Dijkstra(int S) {
memset(dis, -, sizeof(dis));
while (!h.empty()) h.pop();
dis[S] = , add_to_heap(S);
int p;
while (!h.empty()) {
if (dis[h.top().to] != -) {
h.pop();
continue;
}
p = h.top().to;
dis[p] = h.top().v;
h.pop();
add_to_heap(p);
}
} int main() {
int i, j, x;
n = read();
for (i = ; i <= n; ++i) {
x = read();
for (j = i + ; j <= min(i + x + , n) && !pre[j]; ++j)
pre[j] = , add_edge(j, j - , );
for (j = i + x + ; j <= n && !nxt[j]; ++j)
nxt[j] = , add_edge(j, j + , );
if (i + x <= n) add_edge(i, i + x + , );
else add_edge(i, n + , i + x - n);
}
Dijkstra();
printf("%d\n", dis[n + ]);
return ;
}

BZOJ2259 [Oibh]新型计算机的更多相关文章

  1. [bzoj2259][Oibh]新型计算机_Dijkstra

    新型计算机 bzoj-2259 Oibh 题目大意:给定一个n个数的数列,第i个数为a[i],更改第i个数至x的代价为|x-a[i]|.求最小代价,使得:读入一个数s1后,向后连着读s1个数,然后如s ...

  2. BZOJ2259 [Oibh]新型计算机 【傻逼最短路】

    Description Tim正在摆弄着他设计的"计算机",他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算 ...

  3. 【BZOJ2259】[Oibh]新型计算机 最短路

    [BZOJ2259][Oibh]新型计算机 Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计 ...

  4. 【bzoj2259】[Oibh]新型计算机 堆优化Dijkstra

    题目描述 Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假设输入序列中有 ...

  5. BZOJ_2259_ [Oibh]新型计算机 _最短路

    Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假 ...

  6. bzoj 2259 [Oibh]新型计算机 ——最短路(建图)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 不是 n^2 条边!连那条边权为0的边之后,只要每个位置向它的前一个位置和后一个位置连 ...

  7. bzoj 2259 [Oibh] 新型计算机 —— 最短路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 相邻点之间连边权为1的边,就是水最短路了: 要注意点上的数不能改成负数,但是想一想改成 ...

  8. bzoj 2259: [Oibh]新型计算机 最短路 建模

    Code: #include<cstdio> #include<cstring> #include<algorithm> #include<queue> ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. webService 总结

    Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的 ...

  2. PL/SQL编程-介绍

    pl/sql是一种编程语言,就像java一样java叫做高级编程语言 什么是编程,编程说到底就是对于数据的操作,数据包括数据库存储的和自己定义的变量常量等等数据,对他们进行逻辑化的处理 以实现特定的功 ...

  3. mybatis架构理解

    1. mybatis配置 SqlMapConfig.xml,此文件作为mybatis的全局配置文件,配置了mybatis的运行环境等信息. mapper.xml文件即sql映射文件,文件中配置了操作数 ...

  4. 什么是阻塞式和非阻塞io流?

    阻塞IO:socket 的阻塞模式意味着必须要做完IO 操作(包括错误)才会返回. 非阻塞IO:非阻塞模式下无论操作是否完成都会立刻返回,需要通过其他方式来判断具体操作是否成功. 两者区别: 所谓阻塞 ...

  5. js中获取时间戳

    function conver(){ var date = new Date(); var year = date.getFullYear() var month=date.getMonth()+1; ...

  6. zookeeper可视化管理工具node-zk-browser安装

    一.安装nodejs 1. 下载 wget https://github.com/joyent/node/archive/v0.10.35.tar.gz 2. 解压 3. 安装依赖 yum -y in ...

  7. JAVA基础补漏--文件读取

    public class Test2 { public static void main(String[] args) throws IOException { FileInputStream fis ...

  8. Spring IOC 源码解析(持续)

    如何查看源码 Spring源码下载https://github.com/spring-projects/spring-framework/tags?after=v3.1.0.RC1 eclipse关联 ...

  9. Numpy 数据分析基础

    numpy 库 ndarray : numpy 的关键 a = np.array([1,2,3]) # 轴 a.ndim # 数组长度 a.size # 数组的型 a.shape # 类型 a.dty ...

  10. Gym - 100712G Heavy Coins(二进制枚举)

    https://vjudge.net/problem/Gym-100712G 题意:给出n枚不同价值的硬币和一个总价S,现在要选择尽量多的硬币来大于等于S,要求是比如说现在选择的硬币的总和为sum,那 ...