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…
定义一个二维数组: 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…
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 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. 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)…
        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…
#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…
又重头开始刷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 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目. n <= 8 , k <= n 当为-1 -1时表示输入结束. 随后的n行描述了棋盘的形状:每行有n个字符…
//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; //初…
第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队…
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…
正确代码: #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; 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++;…
题来:链接https://vjudge.net/problem/OpenJ_Bailian-132 J - 棋盘问题 1.题目: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C.Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目. n <= 8 , k…
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个单位,3. 移动到当前位置的二倍处.输出移动的最少次数. 解题思路 使用搜索,准确地说是广搜,要记得到达的位置要进行标记,还有就是减枝. 详情见代码实现. 代码实现 #include<cstdio> #include<cstring> #include<iostream>…
[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…
[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的某一数字,不同棋子上标的数字不相同.棋盘上还有一个空格,与空格相邻的棋子可以移到空格中.要求解决的问题是:给出一个初始状态和一个目标状态,找出一种从初始转变成目标状态的移动棋子步数最少的移动步骤.所谓问题的一个状态就是棋子在棋盘上的一种摆法.棋子移动后,状态就会发生改变.解八数码问题实际上就是找出从…
题目链接:https://vjudge.net/problem/POJ-3278 题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子 思路:把题意的三种情况跑bfs,第一个到达目的地的时间最短. #include <iostream> #include <string.h> #include<queue> #include <algorithm> using namespace std; #define rep(i,j,k) for(int…
链接: http://poj.org/problem?id=3278 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 62113   Accepted: 19441 Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a poi…
题意: 在一个有向图中求n头牛从自己的起点走到x再从x走回来的最远距离 思路一开始是暴力跑dij…… 讲道理不太可能…… 然后就百度了一下 才知道把矩阵转置的话就只需要求两次x的单源最短路…… /* *********************************************** Author :Sun Yuefeng Created Time :2016/10/22 20:09:36 File Name :A.cpp *******************************…
题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cstdlib> #include<cmath> #include<cstdio> #include<string> #include<stack> #in…
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> using namespace std; ] = { , - }; struct node { int x, step; } s, ss; int bfs(int n, int k) { queue<node>q, qq; s.x =…
求最小生成树是否唯一 求一遍最小生成树再求一遍次小生成树 看看值是否相等就可以 #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<string> #define cl(a,b) memset(a,b,sizeof(a)) #define debug(x) cerr<<#x<…