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

题意:

  有一段程序,给你一个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. (转载) 清理缓存 IPackageStatsObserver

    清理缓存 IPackageStatsObserver 2016-04-10 13:40 2288人阅读 评论(0) 收藏 举报  分类: android(59)  版权声明:本文为博主原创文章,未经博 ...

  2. 《剑指offer》二叉搜索树与双向链表

    一.题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向 二.输入描述 输入一棵二叉搜索树 三.输出描述 将该二叉搜索树转换成一个 ...

  3. UWP连接mysql 实现数据远程备份

    昨晚吃饭的时候突然觉得我们这个UWP应该添个数据备份的功能,不然换手机,换电脑之后数据库就全没了... 一开始是想用微软提供的AZURE的,没想到这玩意又没什么资料而且申请试用的时候还让我交身份证照片 ...

  4. MVC 单元测试xUnit初探

    对于.NET项目 Web Api的业务逻辑后台开发[特别是做Web Api接口]而言,编写单元测试用例,会极大的减轻代码帮助与运行的方式.然而使用测试框架,相对于自带的,我更加推荐是用xUnit.ne ...

  5. MingW和cygwin的区别(转)

    个人总结:读完这段文字需要5分钟 总结: MingW https://zh.wikipedia.org/wiki/MinGW Cygwin https://zh.wikipedia.org/wiki/ ...

  6. 题解 P3372 【【模板】线段树1 】(zkw)

    看了一下题解里的zkw线段树,感觉讲的不是很清楚啊(可能有清楚的但是我没翻到,望大佬勿怪). 决定自己写一篇...希望大家能看明白... zkw线段树是一种优秀的非递归线段树,速度比普通线段树快两道三 ...

  7. Redis加入Centos Linux开机启动

    Redis加入Centos Linux开机启动 网上有很多redis在linux下自动启动的例子,实现的方式很多,很多都是参考一个老外流传出来启动的例子,其实直接使用是不行,而且有很多地方有一些语法错 ...

  8. Objective-C的陷阱与缺陷

    Objective-C是一个强大而且非常有用的语言,但是同样也是有一点危险的.这次主题是受到一篇有关C++陷阱的文章启发,来聊聊Objective-C和Cocoa中的陷阱. 简介 我将和Horstma ...

  9. &lt;转&gt;Openstack ceilometer 宿主机监控模块扩展

    <Openstack ceilometer监控项扩展>( http://eccp.csdb.cn/blog/?p=352 )主要介绍了对虚拟机监控项扩展, 比較简单.怎样在ceilomet ...

  10. moble 设备多指手势识别 (tap , double_tap , pinch)

    function(){ elem.addEventListener('touchstart', start , false) elem.addEventListener('touchend', end ...