然而并不会做。

最后就照着题解码了一遍/kk

真的好长啊。看时间就知道写了多久...

upd in 2022:

我现在已经找不到原题面是什么了(

不过感觉把这样一篇不算题解的东西放进“题解”里,多少有点不合适呢()

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cg[9] = {1,2,6,24,120,720,5040,40320};
char s[15];
int n,step,mark[380001];
ll v;
struct node{
ll a;
int s;
}p[400001],now,ad;
ll find(ll v)
{
int ss[15];
for(int i = 9;i >= 1;i --)
{
ss[i] = v % 10;
v /= 10;
}
ll ret = 0;
for(int i = 1;i <= 8;i ++)
{
int x = 0;
for(int j = i + 1;j <= 9;j ++)
if(ss[i] > ss[j]) x ++;
ret += x * cg[8 - i];
}
return ret;
}
ll chg1(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[1];
tmp[1] = tmp[4]; tmp[4] = tmp[5]; tmp[5] = tmp[2]; tmp[2] = t;x = 0;
for(int i=1; i<=9; i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg2(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[1];
tmp[1] = tmp[2];tmp[2] = tmp[5];tmp[5] = tmp[4];tmp[4] = t;x = 0;
for(int i = 1;i <= 9;i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg3(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[2];tmp[2] = tmp[5];tmp[5] = tmp[6];tmp[6] = tmp[3];tmp[3] = t; x=0;
for(int i = 1;i <= 9;i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg4(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10; x /= 10;
}
ll t = tmp[2]; tmp[2] = tmp[3];tmp[3] = tmp[6]; tmp[6] = tmp[5]; tmp[5] = t; x = 0;
for(int i = 1;i <= 9;i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg5(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i--)
{
tmp[i] = x % 10;x /= 10;
}
ll t = tmp[4];tmp[4]=tmp[7];tmp[7]=tmp[8];tmp[8]=tmp[5];tmp[5]=t;x=0;
for(int i = 1;i <= 9;i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg6(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[4];tmp[4] = tmp[5];tmp[5] = tmp[8];tmp[8] = tmp[7];tmp[7] = t;x = 0;
for(int i = 1;i <= 9;i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
ll chg7(ll x)
{
ll tmp[10];
for(int i = 9;i >= 1;i --)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[5];
tmp[5] = tmp[8];tmp[8] = tmp[9];tmp[9] = tmp[6];tmp[6] = t;x = 0;
for(int i = 1;i <= 9;i ++)
{
x*=10;
x+=tmp[i];
}
return x;
}
ll chg8(ll x)
{
ll tmp[10];
for(int i = 9; i >= 1; i--)
{
tmp[i] = x % 10;
x /= 10;
}
ll t = tmp[5];
tmp[5] = tmp[6]; tmp[6] = tmp[9]; tmp[9] = tmp[8]; tmp[8] = t;x = 0;
for(int i = 1; i <= 9; i ++)
{
x *= 10;
x += tmp[i];
}
return x;
}
int bfs()
{
int st = 0,ed = 0;
p[ed].a = v, p[ed].s = 0;
ed ++;
mark[find(v)] = 1;
while(st<ed)
{
now = p[st ++];
if(now.a == 123456789LL) return now.s;
if(now.s>step) return -1;
ll w;
w = chg1(now.a);
int ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg2(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg3(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg4(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg5(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg6(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg7(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
w = chg8(now.a);
ww = find(w);
if(mark[ww] == 0)
{
ad.a = w; ad.s = now.s+1;
p[ed ++] = ad;
mark[ww] = 1;
}
}
return -1;
}
int main()
{
scanf("%d",&n);
while(n--)
{
memset(mark,0,sizeof(mark));
scanf("%s",s);
step = s[0]-'0';
v = 0LL;
for(int i = 1; i <= 9; i ++)
{
v *= 10;
v += s[i]-'0';
}
int res = bfs();
printf("%d\n",res);
}
return 0;
}

TOBO的更多相关文章

  1. SP4546 ANARC08A - Tobo or not Tobo IDA*

    题意:

  2. 【WC2013】糖果公园

    Candyland 有一座糖果公园,公园里不仅有美丽的风景.好玩的游乐项目,还有许多免费糖果的发放点,这引来了许多贪吃的小朋友来糖果公园玩. 糖果公园的结构十分奇特,它由 nn 个游览点构成,每个游览 ...

  3. [Web 前端] SuperAgent中文使用文档

    cp from : https://blog.csdn.net/gebitan505/article/details/58585846 superagent是nodejs里一个非常方便的客户端请求代理 ...

  4. MVC中Model BLL层Model模型互转

    MVC中Model BLL层Model模型互转 一. 模型通常可以做2种:充血模型和失血模型,一般做法是模型就是模型,不具备方法来操作,只具有属性,这种叫做失血模型(可能不准确):具备对模型一定的简单 ...

  5. nodejs 框架 中文express 4.xxx中文API手册

       介于最近express 中文文档比较难找的现状,特地找了一个,供大家学习思考 Express 4.x API express 翻译 api文档 中文 --     express() expre ...

  6. ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库

    1.前提: 系统:ubuntu18.04  64位 数据库:mongodb GUI:Robo 3T  2018.3.0 描述: mongodb 安装在局域网内的ubuntu的机子上面,  在win 下 ...

  7. node.js express 中文参考手册

    https://www.runoob.com/w3cnote/express-4-x-api.html 原文地址:https://www.zybuluo.com/bajian/note/444152 ...

随机推荐

  1. Linux reset子系统

    文章代码分析基于linux-5.19.13,架构基于aarch64(ARM64). 1. 前言 复杂IC内部有很多具有独立功能的硬件模块,例如CPU cores.GPU cores.USB控制器.MM ...

  2. linux基础命令及常用命令总结

    1.ls命令 ls命令是最基础的命令之一,作用是列出当前目录下所有的文件和目录.ls命令有很多选项可以使用,比较常用的是-l选项,可以以详细信息的形式列出所有文件和目录的信息. 示例:列出当前目录下的 ...

  3. docker部署zabbix6.0及企业微信发送告警

    1 前言 1.1 实验背景 因zabbix 6.0新增许多新特性,为熟悉界面特意在本地部署一套简易版(未启用HA功能).原本想要在烧制了centos7.9系统树莓派上部署,一查之下armv7果然冷门, ...

  4. Redis解决网络抖动问题

    Redis解决网络抖动问题 所谓网络抖动问题, 简单来说就是防止用户短暂的时间内对同一个接口多次点击访问 这里利用的是redis锁的原子性和with Statement上下文管理器实现, 另外该类还支 ...

  5. Element-ui源码解析(一):项目目录解析

    开始看原码了,我们要开始一些准备工作, 既然是拆代码,那么我们要先把代码搞到手 1.如何下载原码  随便开个项目 npm i element-ui -S 将源码下载到本地 随后在node_module ...

  6. KVM 虚拟机 热插拔硬盘

    新建硬盘 lvm 命令 lvcreate -L 200G -n lv02 ssd01 qemu-img 命令 qemu-img create -f raw test1G.raw 1G dd 命令 dd ...

  7. js: 获取Blob的值

    this.ws.onmessage = async (msg) => { console.log('从服务端获取到了数据') // 从真正服务端发送过来的原始数据时在msg中的data字段 co ...

  8. python将两个列表组合成元组

    point_x = [A_x, B_x, C_x, D_x] point_y = [A_y, B_y, C_y, D_y] points_tulpe = list(zip(point_x, point ...

  9. 医疗知识图谱问答 ——Neo4j 基本操作

    前言 说到问答机器人,就不得不说一下 ChatGPT 啦.一个预训练的大预言模型,只要是人类范畴内的知识,似乎他回答得都井井有条,从写文章到写代码,再到解决零散琐碎的问题,不光震撼到我们普通人,就百度 ...

  10. nlp入门(二) :商品信息可视化与文本分析实战

    源码请到:自然语言处理练习: 学习自然语言处理时候写的一些代码 (gitee.com) 数据来源:麦卡里价格建议挑战Mercari Price Suggestion Challenge | Kaggl ...