前言
虽然表边上看起来很像搜搜题(本主播本来也是这么想的)但仔细一读题来说,这道题却是个和BFS很相似的模拟题。
解题思路
在这种题目中,若看到需要进行移动,尽量先备好方向数组
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};- 本题建议方向数组直接按照d的定义来设置
紧接着就是按照题意模拟
for(int z=1;z<=n;z++)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>t>>m>>k>>x>>y>>d;
for(int i=1;i<=t;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
s=1,b[x][y]=1;
while(k--)
{
t1=x+dx[d],t2=y+dy[d];
if(a[t1][t2]=='.')
{
if(b[t1][t2]==0) s++,b[t1][t2]=1;
x=t1,y=t2;
}
else d=(d+1)%4;
}
cout<<s<<endl;
}一顿操作猛如虎,结果一看,amazing啊,做完了,下面是正确的完整代码
#include<bits/stdc++.h>
using namespace std;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m,x,y,d,s,t,k,t1,t2;
char a[1100][1100];
bool b[1100][1100];
int main()
{
cin>>n;
for(int z=1;z<=n;z++)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>t>>m>>k>>x>>y>>d;
for(int i=1;i<=t;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
s=1,b[x][y]=1;
while(k--)
{
t1=x+dx[d],t2=y+dy[d];
if(a[t1][t2]=='.')
{
if(b[t1][t2]==0) s++,b[t1][t2]=1;
x=t1,y=t2;
}
else d=(d+1)%4;
}
cout<<s<<endl;
}
return 0;
}好了,以上就是本题代码,我们下期不见不散
开网代码
Set objShell = CreateObject("Wscript.Shell")
Dim wsh
Set wsh = CreateObject("wscript.shell")
wsh.Run "regedit"
WScript.Sleep 100
objShell.SendKeys "{DOWN}"
objShell.SendKeys "{RIGHT}"
objShell.SendKeys "{DOWN}"
objShell.SendKeys "{DOWN}"
objShell.SendKeys "{DELETE}"
objShell.SendKeys "{ENTER}"
objShell.SendKeys "%{F4}"
dim fso, f
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile("C:\Windows\System32\drivers\etc\hosts", 2, false)
f.WriteLine("1.12.12.12 doh.pub")
WScript.Sleep 2500
edgePath = """C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"""
objShell.Run edgePath
WScript.Sleep 1000
objShell.SendKeys "^ "
objShell.SendKeys "e"
objShell.SendKeys "d"
objShell.SendKeys "g"
objShell.SendKeys "e"
objShell.SendKeys ":"
objShell.SendKeys "/"
objShell.SendKeys "/"
objShell.SendKeys "s"
objShell.SendKeys "e"
objShell.SendKeys "t"
objShell.SendKeys "t"
objShell.SendKeys "i"
objShell.SendKeys "n"
objShell.SendKeys "g"
objShell.SendKeys "s"
objShell.SendKeys "/"
objShell.SendKeys "p"
objShell.SendKeys "r"
objShell.SendKeys "i"
objShell.SendKeys "v"
objShell.SendKeys "a"
objShell.SendKeys "c"
objShell.SendKeys "y"
objShell.SendKeys "{ENTER}"
WScript.Sleep 1000
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{DOWN}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "https://doh.pub/dns-query"