[kuangbin带你飞]专题一 简单搜索】的更多相关文章

又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每一列是否走过,在此基础上进行DFS即可. 代码如下: #include <iostream> #include <cstring> using namespace std; int n,m,sum; ][]; ] = {}; void dfs(int r,int k){ if(k ==…
A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include<stdio.h> #include<cstring> using namespace std; # define ll long long ; char str[maxn][maxn]; int vis[maxn]; int n,m,num; void dfs(int u,int cnt)…
//Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余数序列是最长的 //经过反复二分验证,436905是能存储198余数序列的最少空间 //但POJ肯定又越界测试了...524286是AC的最低下限,不然铁定RE int main(int i) { int n; while(cin>>n) { if(!n) break; mod[]=%n; //初…
题来:链接https://vjudge.net/problem/OpenJ_Bailian-132 J - 棋盘问题 1.题目: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C.Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目. n <= 8 , k…
        ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Master 335 / 1101 Problem C POJ 3278 Catch That Cow   161 / 503 Problem D POJ 3279 Fliptile 247 / 526 Problem E POJ 1426 Find The Multiple 205 / 330 Pro…
第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队…
定义一个二维数组: 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的二维数组,表示一个迷宫.数据保证有唯一解. Output 左上角到右下角的最短路径,格式如样例所示. Sample Input 0…
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.  Yifenfei’s home is at the countryside, but Merceki’s home is in the center of…
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two m…
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonal…
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目. n <= 8 , k <= n 当为-1 -1时表示输入结束. 随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白…
A - 棋盘问题 POJ - 1321 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目. n <= 8 , k <= n 当为-1 -1时表示输入结束. 随后的n行描述了棋盘的形状:每行有n个字符…
正确代码: #include<iostream> #include<queue> #define N 210 #define inf 0xffffff using namespace std; ],dir[][]={,, ,, -,, ,-},flag; char s[N][N]; struct node{ int x,y,step; }; bool judge(int x,int y) { && x<m && y>= &&…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; ][]; int x, y, ans; ]={,,-}; ]={,,-}; bool sscanf() { ]; scanf("%d%d",&x,&y); && y==) re…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; ][][]; struct dot { int a; int b; int c; int s; }; int x, y, z; bool flag; int clam(int a, int b, int c) { int s;…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; struct node { int x; int y; int s; }; ][]; ][]={{,},{-,},{,},{,-}}; int main() { // freopen("in.in",&quo…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; struct node { int x; int s; }; ]; ]; int chr(int x,int i,int j) { ; ; ; z<= ; z++) { b = x%; x/=; if(i==z) b =…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int x, y; ][]; ][]; ][]; bool flag; ][] = {{,-},{,},{-,},{,},{,}}; bool judge(int cur) { ; i <= x; i++) ; j <= y; j++) { k[i][j] =…
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<queue> #include<cstring> using namespace std; int n, k, c, ans; ]; int main() { // freopen("in.in","r",stdin); while(cin…
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<queue> #include<cstring> using namespace std; struct node { int x; int y; int z; int step; }; ][][]; ][] = {{,,},{,,-},{,,},{,-,},{,,},{-,,}…
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<cstring> using namespace std; struct node { int x; int y; }; int n, k, l, ans; ], h[]; vector<node>dot; void bfs(int a, int b) { ) { ans++;…
[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的某一数字,不同棋子上标的数字不相同.棋盘上还有一个空格,与空格相邻的棋子可以移到空格中.要求解决的问题是:给出一个初始状态和一个目标状态,找出一种从初始转变成目标状态的移动棋子步数最少的移动步骤.所谓问题的一个状态就是棋子在棋盘上的一种摆法.棋子移动后,状态就会发生改变.解八数码问题实际上就是找出从…
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil Deposit…
Escape 参考:http://blog.csdn.net/libin56842/article/details/41909459 [题意]: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消耗一点,在图中有k个炮塔,给出炮塔的射击方向c,射击间隔t,子弹速度v,坐标x,y 问这个人能不能安全到达终点 要求:  1.人不能到达炮塔所在的坐标 2.炮塔会挡住子弹 3.途中遇到子弹是安全的,但是人如果停在这个坐标,而子弹也刚好到这个坐标,人就被射死 4.人可以选择停止不动   思路:其实不难…
    A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找     ID Origin Title   61 / 72 Problem A HDU 1045 Fire Net   52 / 112 Problem B HDU 2444 The Accomodation of Students   45 / 86 Problem C HDU 1083 Courses   44 / 63 Problem D HDU 1281 棋盘游戏   35…
学习最小生成树已经有一段时间了 做一些比较简单的题还算得心应手..花了三天的时间做完了kuangbin的专题 写一个题解出来记录一下(虽然几乎都是模板题) 做完的感想:有很多地方都要注意 n == 1 注意double 的精度问题 poj 1251 模板题 大写字母减去'A'+1即是它的编号 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<m…
        ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HDU 4352 XHXJ's LIS   108 / 195 Problem C HDU 2089 不要62   89 / 222 Problem D HDU 3555 Bomb   59 / 107 Problem E POJ 3252 Round Numbers   47 / 75 Problem…
过去做的都是二分图匹配 即 同一个集合里的点 互相不联通 但是如果延伸到一般图上去 求一个一般图的最大匹配 就要用带花树来解决 带花树模板 用来处理一个无向图上的最大匹配 看了一会还是不懂  抄了一遍kuangbin的模板熟悉了一下 还有一个一般图最大权匹配 保存下来了VFK菊苣的模板题代码当作板子 http://uoj.ac/submission/16359 但愿以后的比赛永远也遇不到 .. 遇到了也能抄对 .. 抄错了也能过 .. R ural1099 kuangbin模板 #include…
百度了好多自学到了次小生成树 理解后其实也很简单 求最小生成树的办法目前遇到了两种 1 prim 记录下两点之间连线中的最长段 F[i][k] 之后枚举两点 若两点之间存在没有在最小生成树中的边 那么尝试加入它 然后为了不成环 要在环中去除一条边 为了达到"次小"的效果 减去最长的 即F[i][k] 求一下此时的数值 不断更新次小值 2 kru 记录下被加入到最小生成树中的线段 然后进行n-1次枚举 每次都跳过一条被记录的边 求一次kru 得到的值为-1或者一个可能成为次小的值 不断更…
        ID Origin Title   17 / 60 Problem A ZOJ 3537 Cake   54 / 105 Problem B LightOJ 1422 Halloween Costumes   59 / 90 Problem C POJ 2955 Brackets   26 / 51 Problem D CodeForces 149D Coloring Brackets   47 / 58 Problem E POJ 1651 Multiplication Puz…