PAT1111 Online Map【最短路】【dfs】】的更多相关文章

题意::从起点到终点的所有的最短路中,找出离终点有X个路口的城市一共有几个 开始我用最短路+DFS从起点开始搜,超时了 换了一种方法,从终点开始搜,AC #include<stdio.h> int N; const int MAX=1e9; ]; ]; ][]; ]; ]; int maxDis; int allPoint; int start,end,shortNum; void dijk() { int i,j,min,rj,from; dis[start]=; ;i<=N;i++)…
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805358663417856 题意: 给定一个图,每天边上有时间和路程信息.要求找到路程最短且时间最短的路径,和时间最短经过的节点最少的路径. 思路: 和昨天写的那个Public Bike Arrangement差不多思路.但是因为要求两个东西所以麻烦一点.感觉好像PAT也在逐渐变难. 都是先求出最短路路径,然后在这些路径中再找到符合条件的一条. 该开始直接写dfs…
明天就要考PAT,为了应付期末已经好久没有刷题了啊啊啊啊,今天开了一道最短路,状态不是很好 1.没有读清题目要求,或者说没有读完题目,明天一定要注意 2.vis初始化的时候从1初始化到n,应该从0开始,以后初始化就从0到n即可 题目大意:给一张地图,两个结点中既有距离也有时间,有的单行有的双向,要求根据地图推荐两条路线:一条是最快到达路线,一条是最短距离的路线. 第一行给出两个整数N和M,表示地图中地点的个数和路径的条数.接下来的M行每一行给出:道路结点编号V1 道路结点编号V2 是否单行线 道…
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8850    Accepted Submission(s): 3267 Problem Description Jimmy experiences a lot of stress at work these days, especiall…
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made b…
Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the ot…
Let's play computer game Description xxxxxxxxx在疫情期间迷上了一款游戏,这个游戏一共有nnn个地点(编号为1--n1--n1--n),他每次从一个地点移动到另外一个地点需要消耗 一定的能量,每一个地点都有一些珠宝,输入中会把每一个地方的珠宝价值估算成一个值. xxxxxxxxx想请聪明的你帮他找出来从编号为sss的地点,到编号为ddd的地点最小要消耗多少能量,消耗这些能量最多获得多少价值的珠宝 Input 第一行输入n,s,dn,s,dn,s,d.其…
旅行 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 18(6 users) Total Accepted: 3(3 users) Rating: Special Judge: No Description "04.24,和Sakura去东京天空树,世界上最暖和的地方天空树的顶上. " "04.26.和Sakura去明治神宫.有人在那里举办婚礼." "04.25.和Sakura去迪士尼.鬼屋非…
You are given a weighed undirected connected graph, consisting of nn vertices and mm edges. You should answer qq queries, the ii-th query is to find the shortest distance between vertices uiui and vivi. Input The first line contains two integers n an…
http://pat.zju.edu.cn/contests/pat-a-practise/1018 在杭州各个点,有很多自助自行车的点,最大容纳点为CMAX,但比较适合的情况是CMAX/2, 现在从起点到终点,在最短路的情况下,调整各个车站的自行车数量使之CMAX/2,问开始时要提供的自行车最少与最后剩余的自行车最少的路径 最短路+DFS 在DFS时加上一个剪枝 if(lenth>dis[first])return ;就可以通过所有点 #include<stdio.h> #define…
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★2544 最短路 基础最短路★3790 最短路径问题基础最短路★2066 一个人的旅行基础最短路(多源多汇,可以建立超级源点和终点)★2112 HDU Today基础最短路★1874 畅通工程续基础最短路★1217 Arbitrage 货币交换 Floyd (或者 Bellman-Ford 判环)★124…
dfs题大杂烩 棋盘问题  POJ - 1321 和经典的八皇后问题一样.  给你一个棋盘,只有#区域可以放棋子,同时同一行和同一列只能有一个棋子. 问你放k个棋子有多少种方案. 很明显,这是搜索题. 因为每一行和每一列只能有一个棋子,所以我们可以从第k行一直到第n行枚举所有放棋子的情况,即我们从当前状态(当前行)dfs到第n行.然后符合添加的,我们就ans++. dfs过程见代码. #include <cstdio> #include <cstring> int n,k,c,wa…
http://poj.org/problem?id=3009 Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. The…
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ 2544    最短路  基础最短路★ 3790    最短路径问题基础最短路★ 2066    一个人的旅行基础最短路(多源多汇,可以建立超级源点和终点)★ 2112    HDU Today基础最短路★ 1874    畅通工程续基础最短路★ 1217    Arbitrage   货币交换…
[HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路(多源多汇,可以建树超等源点和终点)★ 2112 HDU Today 根蒂根基最短路★ 1874 通顺工程续 根蒂根基最短路★ 1217 Arbitrage   货币互换 Floyd (或者 Bellman-Ford 判环)★ 1245 Saving James Bond 策画几何+最短路★ 1317…
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ][]; ][]={, , , , -, , , -, , , , -, -, , -, -}; int n, m; int ans; bool judge(int x, int y){ || x>n || y< || y>m) return false…
Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7337    Accepted Submission(s): 4591 Problem Description There is a rectangular room, covered with square tiles. Each tile is color…
题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep>t剪枝 ②搜到一个解后剪枝 ③当前走到终点最少步数>满足条件还需要走的步数剪枝(关键) ③奇偶剪枝(关键):当前走到终点步数的奇偶性应该与满足条件还需要走的步数奇偶性一致. 其中三四两步放在一步中写:remain=abs(x-ex)+abs(y-ey)-abs(dep-t) 奇偶剪枝的原理:abs(…
这是第一次全部做出来的依次练习了,有一些都是做过两遍了的,但是还是错了几回,更多时候我还是应该多注意下细节,就好像章爷笑我 的一样,像什么vis[]标记没清0,什么格式错误,还有什么题目没看清,还是的注意一下了. 地址:8.1搜索练习 Problem A POJ 2488 A Knight's Journey 题目大意就是说帮你给你个P*Q的棋盘,让马一次全部走完,每个点只能走一次,而且要按照字典序输出(这句话最坑!!!). 这道题做过了两三次了,却老是被那句“字典序输出”给坑死.第一次看到这道…
[题目链接:NYOJ-58] 经典的搜索问题,想必这题用广搜的会比较多,所以我首先使的也是广搜,但其实深搜同样也是可以的. 不考虑剪枝的话,两种方法实践消耗相同,但是深搜相比广搜内存低一点. 我想,因为广搜需要的就是队列,所以相比递归队列更耗内存? 当然DFS并不像上图所说,需要用栈,而是运用递归即可. BFS: 因为BFS是要一个接一个的遍历,所以用到了结构体,来保存坐标和当前所走步数 1.每走一步,通过定义的结构体,从队列中提取a(即上一步的坐标.步数(步数每次累加)) 2.在a的基础上进行…
  fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream> #include<string> #include<algorithm> #include<iterator> #include<sstream>//istringstream #include<cstring> #include<que…
Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15533    Accepted Submission(s): 8911 Problem Description The GeoSurvComp geologic survey company is responsible for detecting underg…
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2449&cid=1181 目前dfs 里的递归还是不很懂,AC代码如下: #include<stdio.h> #include<string.h> ][],vis[][]; int ans; int m,n; void dfs(int i,int j) { if(vis[i][j]||map[i][j]) return; if(i==n&&j==m)…
Counting Sheep Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 14   Accepted Submission(s) : 12 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description A while ago I had trou…
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square pl…
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task is: approa…
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square pl…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8795   Accepted: 3692 Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an…
题目描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on blac…
思路: 可以和1010一个思路.这个抽象的说就是让你求给定图中两点的最短距离,其实dfs的题目能变化的地方就在“终点的回溯处”,在我们到达终点后,再判断一些附加的值(本题里是最短距离是否更新),从而得到答案. 这题有个坑点,就是图里'x',即守卫在的点.通常在dfs之前我们都习惯将map[cur_x][cur_y]设置成无法返回的墙,然后在调用完dfs之后再设回通路,而对于x点来说,我们应该将其设置成'x'而不是通路!不然如果the most optimal way如果是后找到的话,那么我们就会…