zoj 1037 最短路】的更多相关文章

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=37 找规律,水题 #include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { int n; cin>>n; ;i<=n;i++) { cout<<"Scenario #"<<i&…
题意:       给你一个n*m的矩阵,上面只有两种字符,X或者O,每次可以同时改变相同颜色的一个连通块,上下左右连通才算连通,用最小的步数把这个图弄成全是X或者全是O,题意要是没看懂看下面的样例. Sample Input 2 2 2 OX OX 3 3 XOX OXO XOX Sample Output 1 2 Hint For the second sample, one optimal solution is: Step 1. flip (2, 2) XOX OOO XOX Step…
原题链接 题目大意:给出一个格子图,求走完所有节点的最短路径距离. 解法:简单啊,如果都是奇数,可以走一次斜边,其他情况就是长*宽. 参考代码: #include <stdio.h> int main(){ int i,k,m,n; double result; scanf("%d",&k); i=1; while(i<=k){ scanf("%d%d",&m,&n); printf("Scenario #%d:\…
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) ACM总结(fennec) 其实在北京比赛完的时候,我就想写了,不过还是早了点,直到上海比赛结束,大家的心中都不是太好受.郭老师有句话:你们这样做也是对的,不成功就成仁.让我的心也能安慰了不少. 我是从大一下学期开始接触ACM的,那时候我们学校才刚刚起步,siyee,wjiang师兄可以说是我的领路人了…
Scandinavians often make vacation during the Easter holidays in the largest ski resort Are. Are provides fantastic ski conditions, many ski lifts and slopes of various difficulty profiles. However, some lifts go faster than others, and some are so po…
人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个spfa和dinic的模板WA了5发,人老了,可能不适合这种刺激的竞技运动了…… 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2760 Description Given a weighted directed graph, we define the shortest path as the path who has the smallest leng…
题意:好长...从(0,0)走到(w-1,h-1),墓碑不能走,走到传送门只能进去不能走到其他地方,经过传送门时间会变化w(可能为负),其他地方都能上下左右走.如果能无限返老还童输出Never,走不到终点输出Impossible,其他输出最短时间. 思路:没想到是最短路,刚看懂题目还以为是暴搜+剪枝,听到无限返老还童是负权回路才想起来可以用最短路spfa来做.这题就是建边跑spfa就行了,建边方法如题意.注意一下建边的时候终点不能为边的起始,这里WA了,因为到终点了就结束了,如果还能走可能会进入…
题意:单源最短路,给你一些路,给你这些路的长度,给你修这些路的话费,求最短路和最小花费. 析:本质就是一个最短路,不过要维护两个值罢了,在维护花费时要维护的是该路要花多少,而不是总的路线花费. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <…
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1934 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=2722 Description The Gorelians are a warlike rac…
Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highw…
http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <map> #include <iostream> #include <cmath> #include <cstring> #include <queue> using namespace std; const int maxn = 50; bool vis[…
给出 N 种货币 M 条兑换关系 開始时全部的货币S 和有X 块钱 接下来M条关系 A B W1 W2 W3 W4 表示 A->B 所需的手续费为W2块钱  汇率为W1 B->A 所需的手续费为W4块钱  汇率为W3 所以对于输入的一行建两条边 要求到最后能够赚到钱 所以当出现了负圈就可以赚到无限多的钱 #include <cstdio> #include <cstdlib> #include <cstring> #include <climits&g…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5268 题目大意:字符一样并且相邻的即为连通.每次可翻转一个连通块X(O)的颜色,问至少改变几次使得图上所有字符都相等. 解题思路: 1) dfs( 建图 ) ,因为翻转的时候每翻转连通块中一个整个连通块都翻转,这样你可以将其看成一个有边相连的无向图,每个边的两个顶点颜色都不一样. 2) bfs( 寻找最优解 ) , 建完图后就需要翻转计算最优解,可以枚举从每一点开始…
题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存在一系列边(ui,v)使得dis[v]最小(dis[v]表示0到v的距离).这些边能且只能选一条,那么我们自然应该选cost最小的那个边了. #include<iostream> #include<cstdio> #include<cstring> #include<…
Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project. The Marjar Empire has N cities (including the capital)…
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=655 没有理解清题意就硬套模板.所以WA了好几次. 解析看我的还有一篇http://blog.csdn.net/u011026968/article/details/35579035 贴代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #…
题目: Leo has a grid with N rows and M columns. All cells are painted with either black or white initially. Two cells A and B are called connected if they share an edge and they are in the same color, or there exists a cell C connected to both A and B.…
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 2001 2022 2099 2104 21…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
[题意]给出一个图,求 1 -> n的2条 没有重边的最短路. 真◆神题--卡内存卡得我一脸血= =-- [思路] 一开始我的想法是两遍Dijkstra做一次删一次边不就行了么你们还又Dijkstra预处理又最大流的Too naive--结果事实证明从来都是我naive= =--明显是不行的--最大流可能有好几条--但不重边的更少--也许第一次Dijkstra找到的是最短路但不是最后不重边的最短路,然后就这么把边删了显然不对-- 所以我们还是言归正解吧--这道题就是ZOJ 2760的升级版吧--…
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径) Description In the age of television, not many people attend theater perfor…
Beer Problem Time Limit: 2 Seconds      Memory Limit: 32768 KB Everyone knows that World Finals of ACM ICPC 2004 were held in Prague. Besides its greatest architecture and culture, Prague is world famous for its beer. Though drinking too much is prob…
How Many Shortest Path Time Limit: 10 Seconds      Memory Limit: 32768 KB Given a weighted directed graph, we define the shortest path as the path who has the smallest length among all the path connecting the source vertex to the target vertex. And i…
Mission Impossible Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                                         Now a spy is besieged in a maze. He knows that there is a telegraph transmitter  in the maze somewhere. So he…
题目来源:ZOJ Monthly, October 2006, ZOJ2770题目描述:大家都知道,三国时期,蜀国刘备被吴国大都督陆逊打败了.刘备失败的原因是刘备的错误决策.他把军队分成几十个大营,每个大营驻扎一队部队,又用树木编成栅栏,把大营连成一片,称为连营.让我们回到那个时代.陆逊派了很多密探,获得了他的敌人-刘备军队的信息.通过密探,他知道刘备的军队已经分成几十个大营, 这些大营连成一片 (一字排开), 这些大营从左到右用 1…n 编号.第 i 个大营最多能容纳 Ci 个士兵.而且通过观…
转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算法的预处理. 使用邻接矩阵的时间复杂度为O(n^2),用优先队列的复杂度为O((m+n)logn)近似为O(mlogn) (一) 过程 每次选择一个未访问过的到已经访问过(标记为Known)的所有点的集合的最短边,并用这个点进行更新,过程如下: Dv为最短路,而Pv为前面的顶点. 初始 在v1被标记…
A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10000 + 100; int SG[maxn]; vector<int> g[maxn]; int mex(int u) { //minimal exc…
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=508 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.…
新的整理版本版的地址见我新博客 http://www.hrwhisper.me/?p=1952 一.Dijkstra Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算法的预处理. 使用邻接矩阵的时间复杂度为O(n^2),用优先队列的复杂度为O((m+n)logn)近似为O(mlogn) (一)  过程 每次选择一个未访问过的到已经访问过(标记为Known)的所有点的集合的最短边,并用这个点进行更新,过程如下: Dv为最短路,而Pv为前面的顶点.…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以1~n编号一字排开,第i个大营最多能容纳Ci个士兵.而且通过观察刘备军队的动静,陆逊可以估计到从第i个大营到第j个大营至少有多少士兵.最后,陆逊必须估计出刘备最少有多少士兵,这样他才知道要派多少士兵去烧刘备的大营.为陆逊估计出刘备军队至少有多少士兵.然而,陆逊的估计可能不是很精确,如果不能很精确地估…