HDU4889 Scary Path Finding Algorithm
Fackyyj solved this problem at first glance, after that he opened someone's submission, spotted the following code:
long long spfa_slf() {
int n,m;
cin >> n >> m; vector<pair<int,int> > edges111111;
for(int i = ;i < m;i++) {
int x,y,w;
cin >> x >> y >> w;
edgesxx.push_back(make_pair(y,w));
} deque<int> q;
vector<long long> dist(n+, ~0ULL>>);
vector<bool> inQueue(n+, false);
dist11 = ; q.push_back(); inQueue11 = true; int doge = ;
while(!q.empty()) {
int x = q.front(); q.pop_front();
if(doge++ > C) {
puts("doge");
return ;
}
for(vector<pair<int,int> >::iterator it = edgesxx.begin();
it != edgesxx.end();++it) {
int y = it->first;
int w = it->second;
if(distyy > distxx + w) {
distyy = distxx + w;
if(!inQueueyy) {
inQueueyy = true;
if(!q.empty() && distyy > distq.front()q.front())
q.push_back(y);
else
q.push_front(y);
}
}
}
inQueuexx = false;
}
return distnn;
}
Fackyyj's face lit up with an evil smile. He immediately clicked button "Challenge!", but due to a hard disk failure, all of his test case generators were lost! Fackyyj had no interest on recreating his precise generators, so he asked you to write one. The generator should be able to generate a test case with at most 100 vertices, and it must be able to fail the above code, i.e. let the above code print "doge". It should NOT contain any negative-cost loop.
For those guys who doesn't know C++, Fackyyj explain the general idea of the above algorithm by the following psuedo-code:
InputInput contains several test cases, please process till EOF.
For each test case, there will be a single line containing an integer C. It is the constant C in the above code. (C <= 23333333)OutputFor each test case, on the first line, print two integers, n and m, indicating the number of vertices and the number of edges of your graph. Next m lines, on each line print x y w, means there is a road from x to y, cost w.
1 ≤ n ≤ 100,0 ≤ m ≤ n(n-1),|w| < 2 31. Note that your output shouldn't contain any negative-cost loop.Sample Input
1
Sample Output
4 3
1 2 1
2 3 1
3 4 1
图论 愉悦脑洞题 卡SPFA
给了一个SPFA的SLF优化程序,让你把它卡掉。
这个SLF的机制大概是每次更新完,如果被更新的点dis比队头dis小,就把它插到队头。
根据这个性质,只要造出数据让它多出许多遍重复的更新即可
http://blog.csdn.net/u012221059/article/details/38336633
↑这里有张图可以很直观地说明问题。可以发现,随着三角数量的增长,复杂度成指数级上升。
莫慌,不加这个鬼畜优化的普通SPFA,复杂度上界还是$O(NM)$的
注释掉的部分可以卡出一定的效果,但是卡不到指数级的样子。
注意输出顺序也很关键。
那么问题来了,我为什么要花时间写这么道没意义的破题?
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
int main(){
// freopen("in.txt","w",stdout);
int i,j,C;
while(scanf("%d",&C)!=EOF){
int n=,m=;
// int n=99,m=98/2*3;
printf("%d %d\n",n,m);
/* for(i=3;i<=n;i+=2){
printf("%d %d %d\n",i-2,i,-(1<<(i-1)));
}
for(i=1;i<=n-2;i+=2){
printf("%d %d %d\n",i,i+1,0);
}
for(i=2;i<=n;i+=2){
printf("%d %d %d\n",i,i+1,-(1<<(i-2)));
}*/
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,);
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,-(<<(-i)));
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,-(<<(-i-)));
}
return ;
}
HDU4889 Scary Path Finding Algorithm的更多相关文章
- HDU 4889 Scary Path Finding Algorithm
其实这个题是抄的题解啦…… 题解给了一个图,按照那个图模拟一遍大概就能理解了. 题意: 有一段程序,给你一个C值(程序中某常量),让你构造一组数据,使程序输出"doge" 那段代码 ...
- 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. ...
- SPFA(Shortest Path Faster Algorithm)
特别说明 本文转载自三金(frinemore)的博客: 点这 前言 1.关于SPFA,它没死. 2.接下来的所有代码,都是自己手写的(未检查正确性,补充的代码有检查过,是对的),有错误请帮忙指出. S ...
- 2014 Multi-University Training Contest 3
官方解题报告http://blog.sina.com.cn/s/blog_a19ad7a10102uyiq.html Wow! Such Sequence! http://acm.hdu.edu.cn ...
- Awesome Go
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Go 语言相关的优秀框架,库及软件列表
If you see a package or project here that is no longer maintained or is not a good fit, please submi ...
- Awesome Go (http://awesome-go.com/)
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software
Awesome Go financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...
- [JOI 2017 Final] 足球 (建图,最短路)
题面 题解 我们可以总结出球的两种状态,要么自己飞,要么在球员脚下被带飞. 自己飞的情况下,他只能单向直线运动,每一步代价为A,被带飞可以乱走,每一步代价为C. 从自己飞到被带飞需要一个距离自己最近的 ...
随机推荐
- VS2010安装MVC3出错
开始已经在电脑上安装了VS2010以及SP1,还装了MVC4的相关升级包.最后项目中又要用MVC3,然后又去安装MVC3的安装包,但是在安装的过程就出现了问题.一直安装不成功,最后在 ...
- 「日常训练」「小专题·图论」 Frogger (1-1)
题意 分析 变形的dijkstra. 分析题意之后补充. 代码 // Origin: // Theme: Graph Theory (Basic) // Date: 080518 // Author: ...
- AM5728通过GPMC接口与FPGA高速数据通信实现
硬件:AM5728开发板:Artix-7开发板软件:Linux am57xx-evm 4.4.19:Vivado 2015.2作者:杭州矢志信息科技有限公司邮箱:admin@sysjoint.com ...
- MyBatis实例教程--以接口的方式编程
以接口的方式编程: 只需要修改两个地方即可, 1.mapper.xml(实体类)配置文件, 注意mapper的namespace的名字是mapper对象的完整路径名com.xiamen.mapper. ...
- NHibernate3.3.3 学习笔记1
前言 昨天在园友的介绍下,我找了一本学习NHibernate的书:<NHibernate 3 Beginner’s Guide>. 第一章我直接跳过了,因为是英文版的看起来很吃力,且第一章 ...
- 【积累】LinqToSql复合查询结果转DataTable数据
最近的项目用到了大量的复合查询结果用于数据源,绑定到数据控件上. 为了方便,我们把它转换成DataTable的数据源形式.请看下面的示例: 1)思考自己需要的数据,然后组合,因此创建一个新的类: // ...
- CentOS6.8单独编译安装PHP gd库扩展
# PHP-GD安装 #在安装之前可以先更新一下yum源,可以使用国内的阿里云源 yum -y install libjpeg-turbo-devel yum -y install freetype- ...
- iOS-登录发送验证码时60秒倒计时,直接用
__block NSInteger timeout= ; //倒计时时间 KWeakSelf dispatch_queue_t queue = dispatch_get_global_queue(DI ...
- 集显也能硬件编码:Intel SDK && 各种音视频编解码学习详解
http://blog.sina.com.cn/s/blog_4155bb1d0100soq9.html INTEL MEDIA SDK是INTEL推出的基于其内建显示核心的编解码技术,我们在播放高清 ...
- esayui combotree 只能选择子节点
esayui combotree 只能选择子节点用onBeforeSelect:参数是node,节点被选中之前触发,返回false取消选择动作. 网上找了好多都没一个可用的,要想知道他是子节点还是根节 ...