首页 > 其他分享 >【搜索】 FZU 2188 过河I

【搜索】 FZU 2188 过河I

时间:2023-07-05 20:32:19浏览次数:34  
标签:2188 过河 int res LL FZU vis include define


bfs搜索,x,y和船停的地方。

#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 50005
#define maxm 300005
#define eps 1e-3
#define mod 9999677
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid 
#define rson o<<1 | 1, mid+1, R
#define pii pair<int, int>
#pragma comment(linker, "/STACK:16777216")
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
//head

struct node
{
	int x, y, t, u;
	node() {}
	node(int x, int y, int t, int u) : x(x), y(y), t(t), u(u) {}
};

queue<node> q;
int vis[2][205][205];
int n, nx, ny;

void bfs()
{
	int ans = -1;
	memset(vis, 0,  sizeof vis);
	vis[0][nx][ny] = true;
	while(!q.empty()) {
		int x = q.front().x, y = q.front().y;
		int t = q.front().t, u = q.front().u;
		q.pop();
	//	printf("AAA %d %d %d\n", x, y ,u);
		int xx = nx - x, yy = ny - y;
		if(x == 0 && y == 0) {
			ans = t;
			break;
		}
		if(u == 0) {
			for(int i = 0; i <= n && i <= x; i++)
				for(int j = 0; i + j <= n && j <= y; j++) {
					if(i == 0 && j == 0) continue;
					if(i && j > i) break;
					if(x - i && y - j > x - i) continue;
					if(xx + i && (yy + j) > xx + i) continue;
					if(!vis[1][x-i][y-j]) vis[1][x-i][y-j] = true, q.push(node(x - i, y - j, t+1, 1));
				}
		}
		else {
			for(int i = 0; i <= n && i <= xx; i++)
				for(int j = 0; i + j <= n && j <= yy; j++) {
					if(i == 0 && j == 0) continue;
					if(i && j > i) break;
					if(xx - i && yy - j > xx - i) continue;
					if(x + i && (y + j) > x + i) continue;
					if(!vis[0][x+i][y+j]) vis[0][x+i][y+j] = true, q.push(node(x + i, y + j, t+1, 0));
				}
		}
	}
	printf("%d\n", ans);
}

void work()
{
	if(nx && nx < ny) {
		printf("-1\n");
		return;
	}
	while(!q.empty()) q.pop();
	q.push(node(nx, ny, 0, 0));
	bfs();
}

int main()
{
	while(scanf("%d%d%d", &nx, &ny, &n)!=EOF) {
		work();
	}

	
	return 0;
}





标签:2188,过河,int,res,LL,FZU,vis,include,define
From: https://blog.51cto.com/u_8692734/6634980

相关文章

  • FZU 2236(离散化+树状数组)
    【离散化】借此题记一下离散化。离散化:当题目数据很大时,但数的个数不多,可以采用离散化,降低数值,便于计算。例如数列{89,14,9,1000,2};离散化后:{4,3,2,5,1};(此操作后,数值整体降低,甚至可以当数组下标使用了)具体操作参见本题代码。离散化三部曲:1.数组ha[]存储所有存在过的......
  • 过河卒
     /#include<iostream>//usingnamespacestd;//boolvis[25][25];//longlongstep[25][25];//就是dp数组//intmain()//{// step[1][1]=1;// intn,m,x,y;// cin>>n>>m>>x>>y;// n++;// m++;// x++;// y++;// vis[x][y]=1;// vi......
  • [NOIP2002 普及组] 过河卒
    [NOIP2002普及组]过河卒题目描述棋盘上\(A\)点有一个过河卒,需要走到目标\(B\)点。卒行走的规则:可以向下、或者向右。同时在棋盘上\(C\)点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。棋盘用坐标表示,\(A\)点\((0......
  • [省选联考2023] 过河卒
    [省选联考2023]过河卒题目背景棋盘上有一个过河卒,需要走到底线。卒行走的规则是可以向左移动一格,向右移动一格或者向前移动一格。同时在棋盘上有两个另一方的棋子,需要拦截这个卒走到底线。这两个棋子的走法和帅一致,可以走到前后左右四个方向上相邻的格子。因此本题可以称为“......
  • FZU Problem 1894 志愿者选拔 单调队列
    题目:http://acm.fzu.edu.cn/problem.php?pid=1894题意:ProblemDescription世博会马上就要开幕了,福州大学组织了一次志愿者选拔活动。参加志愿者选拔的同学们排队接受面试官们的面试。参加面试的同学们按照先来先面试并且先结束的原则接受面试官们的考查。面试......
  • 联合省选2023 D2T1 过河卒
    我们可以先\(dp\),设\(f_{i,j,k,l}\)和\(g_{i,j,k,l}\)表示当前三个棋子分别在点\(i,j,k\),目前轮到\(l\)走,谁胜利,最终会走多少步。然后我们发现,变成一个有向图博弈。并且\(l\)是由\(i,j,k\)的奇偶性唯一确定的。就可以在图上直接做了。首先我们发现,我们其实可以把初始......
  • kuangbin专题一 简单搜索 点火游戏(FZU-2150)
    FireGameDescriptionFatbrotherandMazeareplayingakindofspecial(hentai)gameonanN*Mboard(Nrows,Mcolumns).Atthebeginning,eachgridofthisboardisconsistingofgrassorjustemptyandthentheystarttofireallthegrass.Firstlyt......
  • 「解题报告」P9169 [省选联考 2023] 过河卒
    挺套路的博弈论,实际上就是GameonGraph与GameonGraph,但是考场上多测没清空挂了。寄。并且不过ABC那个官方题解好像给的是\(O(m\logn)\)的做法,放这题是过不去的啦x首先显然三个棋子压状态大概是\(10^6\)级别的,多测\(T=10\),那么猜测是一个\(O(Tn^6)\)的做法。......
  • 蓝桥-13届-青蛙过河
    看完没什么思路就类似于看完一个自然语言描述的问题后,没法把它转换编程模型题目的意思是y至少要多大,才能足够青蛙跳2x次因为跳跃过程是可逆的,于是能否往返跳2x次等价于同向跳2x次由于当y=n时,青蛙不需要踩任何石头直接跳过去,于是y一定是小于等于n的一个数照这个数我们可以使用......
  • 摸着OpenAI过河,百度文心一言能否“重拳出击”?
    “文心一言”对标ChatGPT,饱含争议。文心一言作为一款语言大模型,并提出了自己在技术对就业的影响方面的理解,现阶段正处于摸着OpenAI过河的时候,路该如何走?GPT-4太惊艳,压力......