然而并不会做。

最后就照着题解码了一遍/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. Unity UGUI的Mask(遮罩)组件的介绍及使用

    Unity UGUI的Mask(遮罩)组件的介绍及使用 1. 什么是Mask组件? Mask(遮罩)组件是Unity UGUI中的一个重要组件,用于限制子对象的可见区域.通过设置遮罩组件,可以实现一些 ...

  2. 深度学习(五)——DatadLoader的使用

    一.DataLoader简介 官网地址: torch.utils.data - PyTorch 2.0 documentation 1. DataLoder类 class torch.utils.da ...

  3. 【调制解调】PM 调相

    说明 学习数字信号处理算法时整理的学习笔记.同系列文章目录可见 <DSP 学习之路>目录,代码已上传到 Github - ModulationAndDemodulation.本篇介绍 PM ...

  4. Codeforces Round #885 (Div. 2) A-D

    比赛链接 A 代码 #include <bits/stdc++.h> using namespace std; using ll = long long; bool solve() { i ...

  5. Centos7中Oracle占用CPU过高(解决方案)

    Centos7中Oracle占用CPU过高(解决方案) 前言: 99%的问题几乎都是SQL的问题,一般SQL可能会出现以下几种情况: 相关SQL搜索条件没有加索引 索引失效 联合查询过多 数据量过大 ...

  6. PostgreSql: 安装与链接

    环境介绍 使用宝塔面板,在阿里云中安装PostgreSql,并使用DataGrip在本地进行链接 postgresql 配置 安装postgresql 在宝塔中安装postgresql 管理器 在此处 ...

  7. AB实验遇到用户不均匀怎么办?—— vivo游戏中心业务实践经验分享

    作者:vivo 互联网数据分析团队 - Li Bingchao AB实验是业务不断迭代.更新时最高效的验证方法之一:但在进行AB实验效果评估时需要特别关注"用户不均匀"的问题,稍不 ...

  8. Avalonia 列表拖拽替换

    实现目标,在一个ListBox中选择一个子项进行拖拽到另一个ListBox中,拖拽到某一子项区域进行替换 下面是axaml代码 1 <ListBox 2 Name="consumabl ...

  9. 【Nacos篇】Nacos基本操作及配置

    官方文档:https://nacos.io/zh-cn/docs/v2/ecology/use-nacos-with-spring-cloud.html 前置条件:SpringCloud脚手架 单机模 ...

  10. VMware三种连接模式的区别

    安装了vm软件后,该软件会虚拟出两张虚拟网卡vmnet1和vmnet8 网卡在控制面板->网络和internet->更改适配器设置 三种网络连接模式: 桥接模式:使用主机的无线网卡或者有线 ...