博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ2259 [Oibh]新型计算机
阅读量:4678 次
发布时间:2019-06-09

本文共 2590 字,大约阅读时间需要 8 分钟。

话说hzwer你在坑爹?、、、

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

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

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

 

1 /************************************************************** 2     Problem: 2259 3     User: rausen 4     Language: C++ 5     Result: Accepted 6     Time:3220 ms 7     Memory:52884 kb 8 ****************************************************************/ 9  10 #include 
11 #include
12 #include
13 #include
14 15 using namespace std;16 typedef long long ll;17 const int N = 1000005;18 const int M = 3000005;19 20 int n, tot;21 int dis[N], first[N];22 bool vis[N], pre[N], nxt[N];23 24 struct edges {25 int next, to, v;26 edges() {}27 edges(int _n, int _t, int _v) : next(_n), to(_t), v(_v) {}28 } e[M];29 30 struct heap_node {31 int v, to;32 heap_node() {}33 heap_node(int _v, int _to) : v(_v), to(_to) {}34 35 inline bool operator < (const heap_node &b) const {36 return v > b.v;37 }38 };39 40 priority_queue
h;41 42 inline int read() {43 int x = 0;44 char ch = getchar();45 while (ch < '0' || '9' < ch)46 ch = getchar();47 while ('0' <= ch && ch <= '9') {48 x = x * 10 + ch - '0';49 ch = getchar();50 }51 return x;52 }53 54 void add_edge(int x, int y, int z) {55 e[++tot] = edges(first[x], y, z);56 first[x] = tot;57 }58 59 inline void add_to_heap(const int p) {60 for (int x = first[p]; x; x = e[x].next)61 if (dis[e[x].to] == -1)62 h.push(heap_node(e[x].v + dis[p], e[x].to));63 }64 65 void Dijkstra(int S) {66 memset(dis, -1, sizeof(dis));67 while (!h.empty()) h.pop();68 dis[S] = 0, add_to_heap(S);69 int p;70 while (!h.empty()) {71 if (dis[h.top().to] != -1) {72 h.pop();73 continue;74 }75 p = h.top().to;76 dis[p] = h.top().v;77 h.pop();78 add_to_heap(p);79 }80 }81 82 int main() {83 int i, j, x;84 n = read();85 for (i = 1; i <= n; ++i) {86 x = read();87 for (j = i + 1; j <= min(i + x + 1, n) && !pre[j]; ++j)88 pre[j] = 1, add_edge(j, j - 1, 1);89 for (j = i + x + 1; j <= n && !nxt[j]; ++j)90 nxt[j] = 1, add_edge(j, j + 1, 1);91 if (i + x <= n) add_edge(i, i + x + 1, 0);92 else add_edge(i, n + 1, i + x - n);93 }94 Dijkstra(1);95 printf("%d\n", dis[n + 1]);96 return 0;97 }
View Code

 

转载于:https://www.cnblogs.com/rausen/p/4121679.html

你可能感兴趣的文章
html(5) css
查看>>
Azure Web连接到Azure MySql Db
查看>>
《麻辣江湖》即将上线!
查看>>
Mybatis中mapper.xml文件判断语句中的单双引号问题
查看>>
frameset和frame
查看>>
饥饿的小易(规律,同余大数)
查看>>
ats透明代理
查看>>
PHP 小代码
查看>>
2016/03/16 codes
查看>>
2018年7月21日工作总结
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
【BZOJ4155】[Ipsc2015]Humble Captains
查看>>
【事件】阻止事件的冒泡
查看>>
mac os 安装 geckodriver
查看>>
【数据分析 R语言实战】学习笔记 第十一章 对应分析
查看>>
谁的青春不迷茫
查看>>