然而并不会做。

最后就照着题解码了一遍/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. Blazor前后端框架Known-V1.2.3

    V1.2.3 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. Gitee: https://gitee.com/known/Known Gith ...

  2. 【Docker】部署Redis

    1.下载镜像 #下载最新版Redis镜像 (其实此命令就等同于 : docker pull redis:latest ) docker pull redis # 下载指定版本的Redis镜像 (xxx ...

  3. 处理.git文件夹过大出现臃肿问题-filter-branch和BFG工具

    Git开发手册 git一些不常用的命令记不住,可以查看git开发手册(https://m.php.cn/manual/view/34957.html) 1..git/objects/pack 文件过大 ...

  4. Matlab2014a 找不到 vs2015编译器解决方法

    准备工作 前提: 电脑已经安装 1.Matlab版本2014a 2.VS版本2015 目标: 结合Matlab和VS2015,实现Matlab的GUI文件和.m文件转化为.exe文件,然后可以单独运行 ...

  5. JNI c++ 与 java 通信过程

    JNI(Java Native Interface)是Java提供的一种机制,用于在Java和本地C/C++代码之间进行通信.下面是JNI C++与Java通信的一般过程: 1. 编写Java代码:首 ...

  6. Unity自定义类使用携程--自身不继承MonoBehaviour

    [TOC] 参考: https://www.jianshu.com/p/67f498cb839b 话不多说,直接上代码 1 using System.Collections; 2 using Unit ...

  7. React报错:This is probably not a problem with npm. There is likely additional logging output above.

    解决方案 删除node_modules和package-lock.json,之后运行npm cache clear --force,重新安装模块npm install,另外要注意 npm 5.0版本之 ...

  8. 在Java中List, Set, Map是否继承自Collection接口?

    List和Set是继承自Collection接口的接口,Set不允许重复的项目,List允许重复项目, Set接口派生的类有TreeSet,HashSet,LinkedHashSet. List接口派 ...

  9. docker-compose快速部署elasticsearch-8.x集群+kibana

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 前文<Docker下elasticse ...

  10. 一文了解Gin对Cookie的支持

    1. 引言 本文将从Web应用程序处理请求时需要用户信息,同时HTTP又是无状态协议这个矛盾点出发.从该问题出发,简单描述了解决该问题的Token 机制,进而引出Cookie的实现方案. 基于此我们将 ...