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

题意:

  有一段程序,给你一个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. 关于exsi的虚拟网络

    相关术语: VM Network 默认的网络 VSwitch   (默认)标准交换机 (exsi的内核中) Port groups  (用来定义各个不同vlan) DVSwitch分布式交换机(exs ...

  2. 3dmax实例教程-使用3ds Max 创建一个完整的场景

    本篇教程讲述了利用3ds max创建一个完整的场景. 灵感来源:当我在遇到一些事情睡不着觉的时候我便在努力想象一些别的事情,于是我便想到了这个场景,其实对于我的这个角色我即没有参考图也没有草稿图,有的 ...

  3. 正则效验url

    上篇文章讲到多主题的解决方案:简单暴力的TP5多主题方案 为了简化配置,所以将域名前的协议 http/https 截取了. 后台配置时就需要效验配置的格式是否正确,需要用到的正则代码如下: /*** ...

  4. django 分组统计遇见的问题

    在使用 django 的时候发现了一个坑 例如: In [54]: print(F.objects.all().values("age").annotate(fff=Count(& ...

  5. CDQ分治笔记

    以前一直不会CDQ……然后经常听到dalao们说“这题直接CDQ啊”“CDQ不就秒了吗”的时候我只能瑟瑟发抖QAQ CDQ分治 其实CDQ分治就是二分分治,每次将$[l,r]$的问题划分为$[l,mi ...

  6. matlab 中语句 a(b)的意思

    a=[1 2; 3, 4; 5, 6]; b=[1 3 2 1; 1 2 4 2]; c=a(b) c =                 1     5     3     1 1     3   ...

  7. centos安全配置

    http://www.dedecms.com/knowledge/servers/linux-bsd/2012/0819/8506.html 引言: 我们必须明白:最小的权限+最少的服务=最大的安全 ...

  8. Python学习第二天-编写三级菜单

    编写三级菜单:1. 运行程序输出第一级菜单2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单3. 菜单数据保存在文件中4. 让用户选择是否要退出5. 有返回上一级菜单的功能 # Author: z ...

  9. php持续集成环境笔记

    记录下php集成环境中若干个工具的安装步骤和过程: 安装pear wget http://pear.php.net/go-pear.phar $ php go-pear.phar 使用:pear in ...

  10. Linux 进程间通信(IPC)

    Linux 进程间通信(IPC): Linux系统中除了进程和进程之间通信,我想大家也应该关注用户空间与内核空间是怎样通信的.例如说netlink等等. 除了传统进程间通信外像Socket通信也须要掌 ...