其实这个题是抄的题解啦…… 题解给了一个图,按照那个图模拟一遍大概就能理解了。

题意:

  有一段程序,给你一个C值(程序中某常量),让你构造一组数据,使程序输出"doge"
   那段代码大概是 SPFA的SLF优化。其实题目的意思是让我们构造一组数据,使得总的出队次数大于C。
        数据范围 C<=23,333,333。输出的图中最多有100个点,没有重边、自环、负环。

思路:

  SLF: 设队首元素为 i, 队列中要加入节点 j, 在        时加到队首而不是队尾, 否则和普通的 SPFA 一样加到队尾.

  这个优化是基于贪心的思想,因为出当前结点的的距离越小,那么他可能更新点就越多,从而达到优化的目的。

  因为是贪心,我们可以“欺骗”他一下。
        我们可以让距离比较大的结点加入队列,那么他会比较晚出队,但是,他会经过一系列的会更新原来更新过的结点,那么被更新的点会重新入队。那么被更新点原来的更新路径会重新被更新一次。

 

题解:来自这里

代码: 先在程序中把图建出来,然后在输出图。这样做会简单一些。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <time.h> using namespace std; const int INF = <<;
const int MAXN = ; int myPow(int d, int n) {
int res = ;
while (n>) {
if (n&) res *= d;
d *= d;
n >>= ;
}
return res;
} vector<pair<int, int> > G[MAXN];
int n, m; void getGraph() {
for (int i = ; i < MAXN; i++)
G[i].clear();
n = ;
for (int i = ; i >= ; i--) {
G[n].push_back(make_pair(n+, ));
G[n].push_back(make_pair(n+, (i!=) ? (-myPow(, i-)) : ));
G[n+].push_back(make_pair(n+, -myPow(, i)));
n += ;
}
m = ;
for (int i = ; i <= n; i++)
m += G[i].size();
} void output() {
printf("%d %d\n", n, m);
for (int i = ; i <= n; i++)
for (int j = ; j < G[i].size(); j++)
printf("%d %d %d\n", i, G[i][j].first, G[i][j].second); } int main() {
#ifdef Phantom01
freopen("HDU4889.txt", "r", stdin);
#endif //Phantom01 getGraph();
int C;
while (scanf("%d", &C)!=EOF) {
output();
} return ;
}

HDU 4889 Scary Path Finding Algorithm的更多相关文章

  1. HDU4889 Scary Path Finding Algorithm

    Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find sh ...

  2. Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process

    (THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920. ...

  3. hdu 1973 Prime Path

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Description The ministers of the cabi ...

  4. HDU 5636 Shortest Path 暴力

    Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph ...

  5. hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏

    huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...

  6. hdu 3631 Shortest Path(Floyd)

    题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...

  7. [HDU 1973]--Prime Path(BFS,素数表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Time Limit: 5000/1000 MS (Java/Others ...

  8. hdu 3631 Shortest Path

    floyd算法好像很奇妙的样子.可以做到每次加入一个点再以这个点为中间点去更新最短路,效率是n*n. #include<cstdio> #include<cstring> #i ...

  9. hdu 5385 The path

    http://acm.hdu.edu.cn/showproblem.php?pid=5385 题意: 给定一张n个点m条有向边的图,构造每条边的边权(边权为正整数),令d(x)表示1到x的最短路,使得 ...

随机推荐

  1. Adobe ZXPInstaller 报错 Installation failed because of a file operation error.

    1. Drag a ZXP file or click here to select a file. 拖放一个 zxp 文件或点击打开选择一个 zxp 文件来安装: 2. Installation f ...

  2. (转载)15 个 Android 通用流行框架大全

    15 个 Android 通用流行框架大全 时间:2017-03-20 11:36来源:未知 作者:admin 点击: 2089 次 15 个 Android 通用流行框架大全   1. 缓存 Dis ...

  3. 004.JMS消息结构

    JMS的消息结构类似于HTTP请求的结构分为三部分: 消息头 消息属性 消息体 下面分别说明三部分的内容标准. 1. 消息头 消息头包含消息的识别信息和路由信息,其标准属性如下: 下面介绍的参数都可以 ...

  4. 叁、js中的css

    一.子选择器:用来选择一个父元素直接的子元素,不包括子元素的子元素,它的符号为“>” 注:ie6不支持子代选择器. <!DOCTYPE html PUBLIC "-//W3C// ...

  5. centos7 bond0 双网卡配置

    [root@openldap ~]# ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500 ...

  6. 错误解决:error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

    今天看到一个比较有趣的题目,如下代码,分析输出结果 #include <stdio.h> void num(int &b) { b = 222; return; } int mai ...

  7. MySQL数据类型及后面小括号的意义

    1,数值类型 1.1数值类型的种类 标准 SQL 中的数值类型,包括严格数值类型(INTEGER.SMALLINT.DECIMAL.NUMERIC),以及近似数值数据类型(FLOAT.REAL.DOU ...

  8. LaTeX 表格

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50066137 一些LaTeX中表格的使 ...

  9. 时间就是金钱HNCOI2000(最短路)

    时间就是金钱HNCOI2000 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! 人们总是选时间最短或费用最低的路线 例如, ...

  10. (六)storm-kafka源代码走读之PartitionManager

    PartitionManager算是storm-kafka的核心类了,如今開始简单分析一下.还是先声明一下,metric部分这里不做分析. PartitionManager主要负责的是消息的发送.容错 ...