当前位置:网站首页>立方体IV(暑假每日一题 10)
立方体IV(暑假每日一题 10)
2022-07-31 11:53:00 【sweetheart7-7】
Vincenzo 决定制作立方体 IV,但所有预算只够制作一个正方形迷宫。
它是一个完美的迷宫,每个房间都呈正方形,并具有 4 4 4 扇门(四个边一边 1 1 1 个)。
每个房间里都有一个号码。
一个人只有在下一个房间的号码比当前房间的号码大 1 1 1 的情况下,才能从当前房间移动到下一个房间。
现在,Vincenzo 为所有房间分配了唯一的号码( 1 , 2 , 3 , … S 2 1,2,3,…S^2 1,2,3,…S2)然后将 S 2 S^2 S2 个人放在了迷宫中,每个房间 1 1 1 个,其中 S S S 是迷宫的边长。
能够移动次数最多的人将获胜。
弄清楚谁将成为赢家,以及他将能够到达的房间数量。
输入格式
第一行包含整数 T T T,表示共有 T T T 组测试数据。
每组测试数据第一行包含整数 S S S,表示迷宫的边长。
接下来 S S S 行,每行包含 S S S 个整数,表示具体的迷宫的房间号分布,需注意 1 , 2 , 3 , … S 2 1,2,3,…S^2 1,2,3,…S2 这 S 2 S^2 S2 个数字,每个数字只出现一次。
输出格式
每组数据输出一个结果,每个结果占一行。
结果表示为 Case #x: r d,其中 x x x 是组别编号(从 1 1 1 开始), r r r 是获胜的人最初所在房间的房间号, d d d 是他可以到达的房间数量。
如果有多个人可到达的房间数相同,那么最初所在房间的房间号最小的人将获胜。
数据范围
1 ≤ T ≤ 100 , 1≤T≤100, 1≤T≤100,
1 ≤ S ≤ 1000 1≤S≤1000 1≤S≤1000
输入样例:
2
2
3 4
1 2
3
1 2 9
5 3 8
4 6 7
输出样例:
Case #1: 1 2
Case #2: 6 4
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1010;
int s;
int g[N][N], f[N][N];
int dx[] = {
-1, 0, 1, 0}, dy[] = {
0, 1, 0, -1};
int get(int x, int y, int d){
if(f[x][y] != -1) return f[x][y];
int res = 0;
for(int i = 0; i < 4; i++){
int a = x + dx[i], b = y + dy[i];
if(a >= 1 && a <= s && b >= 1 && b <= s && g[a][b] == g[x][y] + 1){
res = max(res, get(a, b, d + 1));
}
}
return f[x][y] = res + 1;
}
int main(){
int t;
scanf("%d", &t);
for(int k = 1; k <= t; k++){
scanf("%d", &s);
for(int i = 1; i <= s; i++)
for(int j = 1; j <= s; j++)
scanf("%d", &g[i][j]);
memset(f, -1, sizeof f);
int sd = -1, d = -1;
for(int i = 1; i <= s; i++)
for(int j = 1; j <= s; j++){
int r = get(i, j, 1);
if(r > d || r == d && sd > g[i][j]) sd = g[i][j], d = r;
}
printf("Case #%d: %d %d\n", k, sd, d);
}
return 0;
}
边栏推荐
- vb.net 画曲线
- 瑞吉外卖项目:新增菜品与菜品分页查询
- Caused by: 类找不到: org.apache.flink.table.planner.delegation.ParserFactory或者ExecutorFactory
- Read through the interface to call the artifact RestTemplate
- Chrome开发自定义右键菜单实现快速跳转到指定页面
- In Excel using ODBC consumer SAP ABAP CDS view
- 订song餐系统
- IDEA 配置方法注释自动参数
- Standard SQL/JSON - the sobering part
- 5 个开源的 Rust Web 开发框架,你选择哪个?
猜你喜欢

If the value of the enum map does not exist, deserialization is not performed

学自动化测试哪个培训机构好 试听课程后就选了这个地方学习

ESP8266-Arduino编程实例-HDC1008温度湿度传感器驱动

IDEA configure method annotation automatic parameters

Is the working process of the belt you know the story - actionreducerstore

JVS函数公式使用场景介绍

DCM 中间件家族迎来新成员

最新MySql安装教学,非常详细

3.网页信息解析方法:Xpath与BeautifulSoup

下课看着文档走回实验室,我重新拾起了遗忘的SQL运算符
随机推荐
安装MYSQL遇到问题:write configuration file卡主
kernel syscore
Obsidian设置图床
【虚拟化生态平台】树莓派安装虚拟化平台操作流程
文件包含漏洞
LeetCode - 025. 链表中的两数相加
三层架构service、dao、controller层
lotus-local-net 2k v1.17.0-rc4
The most complete phpmyadmin vulnerability summary
JVS开发套件产品定位
JS列表数据通过递归实现树形结构
xmind使用指南(XMind具有下列哪些功能)
Caused by: 类找不到: org.apache.flink.table.planner.delegation.ParserFactory或者ExecutorFactory
MySQL 行级锁(行锁、临键锁、间隙锁)
Experience innovation and iteration through the development of lucky draw mini-programs
Shengxin Weekly Issue 38
deeplab实现自己遥感地质分割数据集
最近两个月谷歌 ad 掉的厉害
数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表
MySQL模糊查询性能优化