话说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. hbase(一)

    1.hbase安装参考 http://blog.csdn.net/wild46cat/article/details/53214159 2.遇到的问题: ERROR: The node /hbase ...

  2. Django REST Framework 学习笔记

    前言: 基于一些不错的RESTful开发组件,可以快速的开发出不错的RESTful API,但如果不了解开发规范的.健壮的RESTful API的基本面,即便优秀的RESTful开发组件摆在面前,也无 ...

  3. SqlHelper简单实现(通过Expression和反射)9.Sql表述对象SqlSession

    此类是整个SqlHelper的另一个核心,基本思想就是通过EntityHelper,ObjectHelper和ExpressionHelper获取拼接Select语句的全部元素,拼接出完整Select ...

  4. RabbitMQ 如何实现对同一个应用的多个节点进行广播

    1.背景 了解过RabbitMQ的Fanout模式,应该知道它原本的Fanout模式就是用来做广播的.但是它的广播有一点区别,来回顾下它的含义:Fanout类型没有路由键的概念,只要队列绑定到了改ex ...

  5. https://www.cnblogs.com/skywang12345/category/455711.html

    https://www.cnblogs.com/skywang12345/category/455711.html

  6. testng失败截图,注解方式调用。

    今天一整天都在研究testng失败截图的方法,参考网上的前辈们的资料,加上自己的理解,终于搞出来了. package com.dengnapianhuahai; /** * 自定义注释 * */ im ...

  7. C++ vector 用法

    转自http://www.cnblogs.com/wang7/archive/2012/04/27/2474138.html#undefined 在c++中,vector是一个十分有用的容器,下面对这 ...

  8. Linux远程管理器xshell和xftp使用教程,以及遇到关闭Xshell后项目也停止的解决方法

    1.xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议. 2.是一个基于 MS windows 平台的功能强大的 ...

  9. node异步流程控制async

    1.串行无关联:async.series(tasks,callback); 多个函数依次执行,之间没有数据交换,其中一个函数出错,后续函数不再执行 async.series({ one: functi ...

  10. Redis学习笔记之Redis单机,伪集群,Sentinel主从复制的安装和配置

    0x00 Redis简介 Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure server). Redis的键值 ...