
dfs / bfs
Let_life_stop
和强者对战才是提升自己最快的方法。
展开
-
[Gym-100625J] 搜索
题目链接:https://cn.vjudge.net/problem/Gym-100625J具体思路:首先,具体思路是两个人一起走到一个点,然后两个人按照同样的道路走出去,听了别人的思路,还有一种特殊情况需要考虑,就是中间一堵墙,两个人都直接在边界上,这个时候可以新加一个点,然后两个人到这个点的开门数都是0,然后三个搜索,新加的点到图里面所有能走的点的最小路径,两个人分别到达图内的点和新加的点...原创 2018-11-17 15:58:08 · 165 阅读 · 0 评论 -
BFS摸板题
题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2141.html代码如下:#include<bits/stdc++.h>using namespace std;int a[101][101];int visited[101];int b[101];int ...原创 2018-05-18 23:28:23 · 178 阅读 · 0 评论 -
C. Cut 'em all!
题目链接:http://codeforces.com/contest/982/problem/C题目大意:就是先给出n个节点,然后再给出n条边,再判断最少去掉多少条边能使剩下的相连的是偶数。具体思路:首先建立好对应关系,然后再进行dfs。判断每一个父亲节点的子节点的个数是不是偶数,如果是偶数就可以砍掉,如果不是偶数,则不可以砍掉。代码如下:#include<bits/stdc...原创 2018-05-25 19:41:21 · 363 阅读 · 0 评论 -
B. Switches and Lamps
B. Switches and Lampstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n switches and m lamps. The i-th switch tu...原创 2018-05-26 16:23:23 · 570 阅读 · 1 评论 -
棋盘问题 poj
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n...原创 2018-05-28 20:59:46 · 609 阅读 · 0 评论 -
D - Fliptile
题目: Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ...原创 2018-05-31 21:47:50 · 365 阅读 · 0 评论 -
Prime Path
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of sec...原创 2018-06-02 19:16:04 · 197 阅读 · 0 评论 -
迷宫问题
定义一个二维数组:int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input一个5 × 5的...原创 2018-06-04 21:58:41 · 237 阅读 · 0 评论 -
I - Interesting Calculator (bfs使用优先队列求步数最小或者花费最小)
题目链接:https://cn.vjudge.net/contest/245287#problem/I代码:使用普通的队列和优先队列相比,优先队列能更快地找到目的变量。#include<iostream>#include<string>#include<cstring>#include<iomanip>#include<s...原创 2018-08-09 15:12:26 · 217 阅读 · 0 评论 -
dfs(通过控制点的编号来得出每个点的坐标)
题目链接:https://cn.vjudge.net/contest/234497#problem/A#include<iostream>#include<string>#include<cstring>#include<iomanip>#include<algorithm>#include<queue>#i...原创 2018-08-15 09:35:45 · 508 阅读 · 0 评论 -
汉诺塔
#include<bits/stdc++.h>using namespace std;# define maxn 1000000+10void tower(int n,char a,char b,char c){ if(n==1) { cout<<a<<" "<<c<<endl; } ...原创 2018-08-27 21:01:31 · 339 阅读 · 0 评论 -
F - A计划
题目链接:https://cn.vjudge.net/contest/254150#problem/Fwa代码:#include<iostream>#include<string>#include<cstring>#include<queue>#include<stdio.h>#include<stack&g...原创 2018-09-15 08:42:08 · 385 阅读 · 0 评论 -
G - DNA sequence HDU - 1560
题目链接:https://vjudge.net/contest/254151#problem/GAC代码:#include<iostream>#include<cstring>#include<string>#include<algorithm>using namespace std;# define inf 0x3f3f3f...原创 2018-09-18 14:27:52 · 244 阅读 · 0 评论 -
J - Borg Maze +getchar 的使用注意(二维字符数组的输入)
题目链接:https://vjudge.net/contest/66965#problem/J具体思路:首先将每个点之间的最短距离求出(bfs),A 或者 S作为起点跑bfs,这样最短距离就求出来了。然后再用最短路的算法求出最小生成树的权值的和就可以了,getchar的注意事项在代码中解释。#include<iostream>#include<string&g...原创 2018-10-07 11:34:27 · 302 阅读 · 0 评论 -
ACM-ICPC北京赛区2018重现赛 A题
题目链接:http://hihocoder.com/contest/icpcbeijing2018/problem/1具体思路:dfs,判断矛盾就可以了。AC代码:#include<iostream>#include<string>#include<cstring>#include<iomanip>#include<alg...原创 2018-11-11 21:36:55 · 1059 阅读 · 0 评论 -
E - Sudoku HDU - 5547 (搜索+暴力)
题目链接:https://cn.vjudge.net/problem/HDU-5547具体思路:对于每一位上,我们可以从1到4挨着去试, 具体判断这一位可不可以的时候,看当前这一位上的行和列有没有冲突,以及他所在的2*2的方格中有没有矛盾的。AC代码:#include <iostream>#include <string>#include <de...原创 2018-12-25 15:37:55 · 271 阅读 · 0 评论