当前位置:网站首页>P8462 「REOI-1」奶油蛋糕
P8462 「REOI-1」奶油蛋糕
2022-08-09 05:11:00 【冷颕】
简单的dfs,我直接上代码了。
#include <iostream>
#include <cstring>
using namespace std;
int maze[51][51];
int len[51][51];
int temp[51][51][1001]; /*(x,y)坐标走过的记录,例如(1,1,1)代表(1,1)走第一次的记录*/
int n,m,x,y;
string s;
bool in(int x,int y)
{
return x>=1&&x<=n&&y>=1&&y<=n;
}
void dfs(int x,int y,int index1) /*dfs暴力搜*/
{
if(index1>=m+1)
{
return;
}
len[x][y]++;
temp[x][y][len[x][y]]=index1;
if(s[index1]=='N')
{
int ty=y+1;
int tx=x;
if(in(tx,ty))
{
dfs(tx,ty,index1+1);
}
}
if(s[index1]=='S')
{
int ty=y-1;
int tx=x;
if(in(tx,ty))
{
dfs(tx,ty,index1+1);
}
}
if(s[index1]=='W')
{
int ty=y;
int tx=x-1;
if(in(tx,ty))
{
dfs(tx,ty,index1+1);
}
}
if(s[index1]=='E')
{
int ty=y;
int tx=x+1;
if(in(tx,ty))
{
dfs(tx,ty,index1+1);
}
}
}
int main()
{
cin>>n>>m>>x>>y;
cin>>s;
memset(temp,-1,sizeof(temp));
dfs(x,y,0); /*x坐标和y坐标与题意一样*/
long long sum=0;
int t=1;
for(int i=1;i<=m;i++)
{
sum=sum+i;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
len[j][n-i+1]++; /*最后一个坐标设为m*/
temp[j][n-i+1][len[j][n-i+1]]=m;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=0;k<len[j][n-i+1];k++) /*每个坐标我们走过了几次*/
{
t=0;
for(int l=temp[j][n-i+1][k]+1;l<temp[j][n-i+1][k+1];l++) /*每个区间阶段求和*/
{
++t;
maze[j][n-i+1]=maze[j][n-i+1]+t; /*0-m进行求和*/
}
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cout<<maze[j][n-i+1]<<" ";
}
cout<<endl;
}
return 0;
}
边栏推荐
- el与data的
- flask——介绍、安装、快速使用、配置文件、路由系统、视图
- 【Harmony OS】【ARK UI】Public Event Module
- TASSEL software imports plink format file error
- CSDN使用方法
- 【HMS Core】【FAQ】【AR Engine】AR Engine FAQ
- Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
- 二分搜索篇
- 【Harmony OS】【ARK UI】ETS 上下文基本操作
- Harmony OS ets ArkUI 】 【 】 development create a view and building layout
猜你喜欢
随机推荐
微服务架构基础 微服务相关概念及基础知识 贺兰的微博
php使用phpoffice/phpspreadsheet导入导出excel表格
浅谈产品降本设计
Shell:数组和函数用法
机器人大赛总结
10.LoadRunner2022社区版安装
【HMS core】【ML kit】机器学习服务常见问题FAQ
制作频谱应用FFT心得
剑指Offer-二叉树路径问题总结
【luogu U142356】Suffix of the Brave (SA) (Chairman Tree) (2 points)
Eureka-Server------单节和集群的搭建
【LeetCode】287. 寻找重复数
matlab simulink球杆控制系统的模糊PID控制设计
perl基础语法归纳
降压模块的使用
C Advanced-C Language File Operation
[UNR #6 A] Noodle-based road (shortest path)
How to choose an APS system, it is necessary to clarify these seven key factors
STM32之vl53l0x读取距离
Pycharm Debug调试使用+代码调试理解