话说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 ;
}

最新文章

  1. 使用 yum 安装 virtualbox 虚拟机
  2. spring JTA多数据源事务管理详细教程
  3. char a[] = &quot;hello&quot;; char c[] = {&#39;h&#39;,&#39;e&#39;,&#39;l&#39;,&#39;l&#39;,&#39;o&#39;}; int b[] = {1, 2, 3, 4, 5};的长度区别,及内存中空间开辟情况
  4. Spark 1.6.1分布式集群环境搭建
  5. 反射+javacsv+scv文件构建资源获取
  6. [Java] 垃圾回收机制 ( Garbage Collection ) 简介
  7. sublime在Mac osx下安装z-codeing(即emmet)
  8. less样式表
  9. SPOJ 130 - Rent your airplane and make money(dp+优化)
  10. 按自己的想法去理解事件和泛型(C#)
  11. mysql数据库封装和 分页查询
  12. vue组件之间的通信以及如何在父组件中调用子组件的方法和属性
  13. cmd 指令
  14. 如何从 VSS 迁移到Team Foundation Server
  15. thinkphp 无限极 评论
  16. chmod a+r file:给所有用户添加读的权限
  17. vs2008 安装部署 启动项
  18. 在jsp中怎么使用Cookie?el表达式中获取cookie的问题
  19. virgo-tomcat访问日志的详细配置
  20. 城市规模越大,工资、GDP、犯罪率越高:4.5星|《规模》

热门文章

  1. HDU 4585 Shaolin(map应用+二分)
  2. Java设计原则—里氏替换原则(转)
  3. linux环境上运行.net core 初探
  4. C#调用小票打印机
  5. 乐观锁的一种实现方式——CAS
  6. win10+eclipse+hadoop2.7.2+maven+local模式直接通过Run as Java Application运行wordcount
  7. Python学习笔记之函数参数传递 传值还是传引用
  8. 20145216史婧瑶《Java程序设计》第一周学习总结
  9. HBase安装过程
  10. How to Enable RPMForge Repository in RHEL/CentOS 7.x/6.x/5.x