BZOJ2259 [Oibh]新型计算机
话说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]新型计算机的更多相关文章
- [bzoj2259][Oibh]新型计算机_Dijkstra
新型计算机 bzoj-2259 Oibh 题目大意:给定一个n个数的数列,第i个数为a[i],更改第i个数至x的代价为|x-a[i]|.求最小代价,使得:读入一个数s1后,向后连着读s1个数,然后如s ...
- BZOJ2259 [Oibh]新型计算机 【傻逼最短路】
Description Tim正在摆弄着他设计的"计算机",他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算 ...
- 【BZOJ2259】[Oibh]新型计算机 最短路
[BZOJ2259][Oibh]新型计算机 Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计 ...
- 【bzoj2259】[Oibh]新型计算机 堆优化Dijkstra
题目描述 Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假设输入序列中有 ...
- BZOJ_2259_ [Oibh]新型计算机 _最短路
Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假 ...
- bzoj 2259 [Oibh]新型计算机 ——最短路(建图)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 不是 n^2 条边!连那条边权为0的边之后,只要每个位置向它的前一个位置和后一个位置连 ...
- bzoj 2259 [Oibh] 新型计算机 —— 最短路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 相邻点之间连边权为1的边,就是水最短路了: 要注意点上的数不能改成负数,但是想一想改成 ...
- bzoj 2259: [Oibh]新型计算机 最短路 建模
Code: #include<cstdio> #include<cstring> #include<algorithm> #include<queue> ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- Python之路——线程池
1 线程基础 1.1 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2 线程同步——锁 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样,其实Python中是伪多线程).但是当线程 ...
- Java GC 标记/清除算法
1) 标记/清除算法是怎么来的? 我们在程序运行期间如果想进行垃圾回收,就必须让GC线程与程序当中的线程互相配合,才能在不影响程序运行的前提下,顺利的将垃圾进行回收. 为了达到这个目的,标记/清除算法 ...
- https://www.cnblogs.com/skywang12345/category/455711.html
https://www.cnblogs.com/skywang12345/category/455711.html
- windows下mysql安装失败的一个解决案例
操作系统:windows8.1,之前安装过mysql,这次安装在配置的最后一部执行“Apply security settings”的过程中弹出经典错误: Access denied for user ...
- Win32GUI代码示例
// Win32UI.cpp : 定义应用程序的入口点. // #include "stdafx.h" #include "Win32UI.h" #includ ...
- iOS开发之XMPPFramework开发基础介绍
1 使用iPhoneXMPP实例 2 修改xmppstream设置 3 基础协议的介绍 协议 协议简介 XEP-0009 在两个XMPP实体间传输XML-RPC编码请求和响应 XEP-0006 使能与 ...
- 在MySQL中使用explain查询SQL的执行计划
1.什么是MySQL执行计划 要对执行计划有个比较好的理解,需要先对MySQL的基础结构及查询基本原理有简单的了解. MySQL本身的功能架构分为三个部分,分别是 应用层.逻辑层.物理层,不只是MyS ...
- 照着官网来安装openstack pike之environment设置
安装openstack前的准备环境: 两个centos7系统的环境:192.168.101.10 node1,192.168.101.11 node2 控制节点node1,计算节点node2 1.统一 ...
- think in java
1.public private protected
- spark SQL学习(案例-统计每日uv)
需求:统计每日uv package wujiadong_sparkSQL import org.apache.spark.sql.{Row, SQLContext} import org.apache ...