p1518 The Tamworth Two
2024-09-05 11:02:57
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=;
char ch[SZ][SZ];
bool vst[SZ][SZ][][SZ][SZ][];
int dx[]={-,,,},dy[]={,,,-}; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
for(int i=;i<=;++i)cin>>ch[i]+;
int fx,fy,cx,cy;
for(int i=;i<=;++i)
{
for(int j=;j<=;++j)
{
if(ch[i][j]=='F')fx=i,fy=j;
if(ch[i][j]=='C')cx=i,cy=j;
}
}
vst[fx][fy][][cx][cy][]=;
int dc=,df=;
int time=;
//cout<<fx<<" "<<fy<<" "<<cx<<" "<<cy<<endl;
for(;;)
{
int nfx=fx+dx[df],nfy=fy+dy[df];
int ncx=cx+dx[dc],ncy=cy+dy[dc];
if(nfx>=&&nfx<=&&nfy>=&&nfy<=&&ch[nfx][nfy]!='*')
{
fx=nfx,fy=nfy;
}
else df=(df+)%;
if(ncx>=&&ncx<=&&ncy>=&&ncy<=&&ch[ncx][ncy]!='*')
{
cx=ncx,cy=ncy;
}
else dc=(dc+)%;
++time;
if(fx==cx&&fy==cy)
{
cout<<time<<endl;
break;
}
if(vst[fx][fy][df][cx][cy][dc]==)
{//cout<<fx<<" "<<fy<<" "<<cx<<" "<<cy<<endl;
cout<<<<endl;
break;
}
vst[fx][fy][df][cx][cy][dc]=;
}
}
return ;
}
最新文章
- usb驱动开发14之设备生命线
- 单例(C#版)
- Leetcode: Insert Delete GetRandom O(1) - Duplicates allowed
- fragment (1)简单示例:定义,界面配置,fragment之间的跳转
- 使用 JAX-RS 简化 REST 应用开发
- 漫谈C语言及如何学习C语言
- BZOJ 3993 [SDOI 2015] 星际战争 解题报告
- Flume+LOG4J+Kafka
- 谈谈渲染,玩玩nginx——前后端分离,转发请求到Tomcat的尝试
- iOS 友盟推送,应用内推送启动图推送闪动黑屏,插屏推送方法报错
- Bilateral Filter
- 10 - JavaSE之网络编程
- NOIP2017感悟
- 执行发送邮件Send方法时,报错:邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for xxx@xxx.com
- python &#39;%r&#39;或者&#39;{!r}&#39;的意思
- [三边定位] C# 演示程序
- non-ZenoAndAcceptingLocation
- html5-figure和figcaption元素
- Shell函数和数组
- [USACO19FEB]Moorio Kart