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. 从自己飞到被带飞需要一个距离自己最近的 ...
随机推荐
- Sql Server 2008 R2数据库中插入中文变成了问号
通过Insert语句插入数据库中,结果中文都变成了乱码.原因是在数据库中有一个属性需要设置,可以通过Sql server manager studio来进行设置,也要可以通过代码来设置 ...
- Qt 隐藏标题栏可移动升级版
在最出的时候,在Qt程序隐藏标题栏的情况下,实现界面可拖拽移动,是鼠标在在程序界面的任意位置都可以,现在这个版本是需要鼠标在程序界面的特定位置开可以 上代码 static QPoint last(0, ...
- 自动化测试元素查找利器firepath介绍
自动化测试查找元素和确定元素xpath路径是否正确在业界有个很好的工具就是firefox 浏览器的 firepath 问题: firefox 最新版本已经不支持firebug和firepath这两个插 ...
- libvirt保持虚拟机运行情况下修改名称
通过virsh list命令能看到虚拟机的列表: [root@compute2 ~]# virsh list Id 名称 状态 ------------------------------------ ...
- 分布式文件系统---GlusterF
1.1 分布式文件系统 1.1.1 什么是分布式文件系统 相对于本机端的文件系统而言,分布式文件系统(英语:Distributed file system, DFS),或是网络文件系统(英语:Ne ...
- 剑指offer-数值的整数次方12
class Solution: def Power(self, base, exponent): # write code here if base==0: return 0 if exponent= ...
- 1013 Battle Over Cities (25 分)(图的遍历or并查集)
这题用并查集或者dfs都可以做 dfs #include<bits/stdc++.h> using namespace std; ; bool mp[N][N]; int n,m,k; b ...
- Z.XML-Cocos2d-x开发笔记
大家都在热火朝天的使用Cocos2d-x引擎做游戏开发,那么大家不妨把过程中解决的关键问题记录在这里,做一个分享! 1.在Android平台下打开网页 1.1修改项目工程源文件 在你的项目工程源文件中 ...
- 转 Using $.ajaxPrefilter() To Configure AJAX Requests In jQuery 1.5
Using $.ajaxPrefilter() To Configure AJAX Requests In jQuery 1.5 Posted February 18, 2011 at 6:29 PM ...
- lintcode-119-编辑距离
119-编辑距离 给出两个单词word1和word2,计算出将word1 转换为word2的最少操作次数. 你总共三种操作方法: 插入一个字符 删除一个字符 替换一个字符 样例 给出 work1=&q ...