首页 > 其他分享 >A Knight's Journey

A Knight's Journey

时间:2023-05-24 20:55:06浏览次数:29  
标签:square Scenario int Knight Journey knight line squares

[ 提交 ] [状态]

题目描述

The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. The world of a knight is the chessboard he is living on. Our knight lives on a chessboard that has a smaller area than a regular 8×88 \times 88×8 board, but it is still rectangular. Can you help this adventurous knight to make travel plans? 

输入

The input begins with a positive integer nnn in the first line. The following lines contain nnn test cases. Each test case consists of a single line with two positive integers ppp and qqq, such that 1≤pq≤261 \le pq \le 261≤pq≤26. This represents a p×qp \times qp×q chessboard, where ppp describes how many different square numbers exist, qqq describes how many different square letters exist. These are the first qqq letters of the Latin alphabet.

输出

The output for every scenario begins with a line containing Scenario #i:, where iii is the number of the scenario starting at 111. Then print a single line containing the lexicographically first path that visits all squares of the chessboard with knight moves followed by an empty line. The path should be given on a single line by concatenating the names of the visited squares. Each square name consists of a capital letter followed by a number.

If no such path exist, you should output impossible on a single line. 

输入输出样例

样例输入 #1

3
1 1
2 3
4 3

样例输出 #1

Scenario #1:
A1

Scenario #2:
impossible

Scenario #3:
A1B3C1A2B4C2A3B1C3A4B2C4
#include<bits/stdc++.h>
using namespace std;
const int N=2020;
int n,m,cnt=1;
int dx[8]={-2,-2,-1,-1,1,1,2,2},dy[8]={-1,1,-2,2,-2,2,-1,1};//这里讲一下为什么是这个顺序
//:其实某位大佬说过,dfs输出字典序,无非就是按顺时针搜索,或者以字典序最小的那个开始搜,到最后搜出来的一定是最小
//int go[8][2] = { {-2,-1},{-2, 1}, {-1,-2},{-1,2}, {1,-2},{1,2},{2,-1},{2,1}};
struct node
{
    int x,y;
    string s;
}k[50];
bool vis[N][N],f;
void dfs(int x,int y,int num)
{
    if(f) return;
    k[num].x=x,k[num].y=y;
    if(num==n*m)
    {
        cout<<"Scenario #"<<cnt++<<":"<<endl;
        for(int i=1;i<=n*m;i++) printf("%c%d",k[i].x-1+'A',k[i].y);
        f=true;
        cout<<endl;
    }
    for(int i=0;i<8;i++)
    {
        int x1=x+dx[i],y1=y+dy[i];
        if(x1>0&&x1<=n&&y1>0&&y1<=m&&!vis[x1][y1]&&!f)
        {
            vis[x1][y1]=true;
            dfs(x1,y1,num+1);
            vis[x1][y1]=false;
        }
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        f=false;
        memset(vis,false,sizeof vis);
        cin>>m>>n;
        vis[1][1]=true;
        dfs(1,1,1);
        if(!f) cout<<"Scenario #"<<cnt++<<":"<<endl<<"impossible"<<endl<<endl; 
    }
    return 0;
}

 

 

标签:square,Scenario,int,Knight,Journey,knight,line,squares
From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17429476.html

相关文章

  • Midjourney|文心一格prompt教程[进阶篇]:Midjourney Prompt 高级参数、各版本差异、官
    Midjourney|文心一格prompt教程[进阶篇]:MidjourneyPrompt高级参数、各版本差异、官方提供常见问题1.MidjourneyPrompt高级参数Quality图片质量是另一个我比较常用的属性,首先需要注意这个参数并不影响分辨率,并不改变分辨率,并不改变分辨率(重要的事情要说三遍)。它改变的更多......
  • Midjourney|文心一格 Prompt:完整参数列表、风格汇总、文生图词典合集
    Midjourney|文心一格Prompt:完整参数列表、风格汇总、文生图词典合集1.Midjourney完整参数列表参数名称调用方法使用案例注意事项V5V4V3niji版本在关键词后加空格,然后带上版本参数:--v或者—v--version或者—versionvibrantcaliforniapoppies--v5......
  • 人手一个 Midjourney,StableStudio 重磅开源!
    人手一个Midjourney,StableStudio重磅开源!StabilityAI公司在上个月19号推出了Alpha版本StableLM大语言模型,包含了30亿和70亿参数,并且支持商用。如今他们再次推出了AI图像生成平台StableStudio,这可是距上次大开发仅过去一个月啊!该平台是DreamStudio开源版的实......
  • Midjourney|文心一格prompt教程[Text Prompt(下篇)]:游戏、实物、人物、风景、动漫、邮票
    Midjourney|文心一格prompt教程[TextPrompt(下篇)]:游戏、实物、人物、风景、动漫、邮票、海报等生成,终极模板教学场景6:游戏Prompt真的越长越好吗?按照Midjourney的官方文档里的说法,并不一定:Promptscanbeverysimple.Singlewords(orevenanemoji!)willproducean......
  • 无界AI绘画基础教程,和Midjourney以及Stable Diffusion哪个更好用?
    本教程收集于:AIGC从入门到精通教程汇总简单的总结Midjourney,StableDiffusion,无界AI的区别?Midjourney,收费,上手容易,做出来高精度的图需要自己掌握好咒语。咒语写不好,像是抽奖。里面的模型基本都是大模型,小模型太少,需要一些辅助机器人或者辅助操作保持画风的一致。StableDiffus......
  • UVA 12177 First Knight
    (提醒:原题面是\(m\)行\(n\)列,这里改成了\(n\)行\(m\)列)首先很好想到设\(dp_{u,v}\)为\((u,v)\)的期望步数\(dp_{u,v}=\begin{cases}\sum_{i=1}^4dp_{u+du_i,v+dv_i}\timesp_i&(u\not=n\operatorname{or}v\not=m)\\0&(u=n\operator......
  • Midjourney 创建私人画图机器人(保姆级教程)
    本教程收集于:AIGC从入门到精通教程汇总之前给大家介绍过了Midjourney的注册教程:AI绘画:Midjourney注册(保姆级教程)也有StableDiffusion(开源)的本地搭建教程:AI数字绘画:stable-diffusion本地部署教程你是不是遇到以下问题:1.Midjourney会员怎么自建绘图服务器,不受其他人的打扰?......
  • Midjourney v4 | 如何结合参考图像来生成AI艺术图
    ​网址:midjourney.com首页展示首页如下图:​编辑第一步:进入社群点击首页右下角“JointheBeta”,进入如下页面:​编辑点击“接受邀请”,验证之后进入​编辑可以点击认证账号,进行注册:​编辑应该不注册也能用,注册之后,左下角有个人信息:​编辑在输入框可以输入一些命令去生......
  • 干货分享:用ChatGPT调教批量出Midjourney咒语,出图效率Nice ,附资料。
    Prompts就是AI绘图的核心竞争力。您是不是觉得用Midjourney生成的图不够完美?又让ChatGPT去生成Prompt,然后效果还不理想?其实ChatGPT你给他投喂资料后,经过调教的ChatGPT,生成的Prompt效果会很不错。文末附《一整套MidJourney指令大全》+《ChatGPTprompt指令大全》资料先看测试......
  • Midjourney 提示词工具(10 个国内外最好最推荐的)
    Midjourney,是一个革命性的基于人工智能的艺术生成器,可以从被称为提示的简单文本描述中生成令人惊叹的图像。Midjourney已经迅速成为艺术家、设计师和营销人员的首选工具(包括像我这样根本不会设计任何东西的无能之辈)。为了帮助你开始使用这个强大的工具,我们汇编了一份15个资源的清......