然而并不会做。

最后就照着题解码了一遍/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. Prometheus-3:一文详解promQL

    读前提示: 本文字数较多且紧凑,最好预留15min一次性看完,好营养,易吸收. promQL详解 Prometheus提供了内置的数据查询语言PromQL(全称为Prometheus Query La ...

  2. 微信小程序 - WXML 模板语法

    [黑马程序员前端微信小程序开发教程,微信小程序从基础到发布全流程_企业级商城实战(含uni-app项目多端部署)] https://www.bilibili.com/video/BV1834y1676 ...

  3. docker ps --no-trunc 与 docker ps

    转载请注明出处: docker ps --no-trunc与docker ps之间的区别在于输出结果的格式. docker ps: 默认情况下,docker ps命令以截断的方式显示结果.这意味着容器 ...

  4. hexo博客Yilia主题首页菜单中文乱码解决方案

    方案一: 菜单设置成中文显示,编辑博客根目录下的_config.yml文件 设置language字段如下: language: zh-Hans 或者 language: zh-CN 取决于你的主题th ...

  5. 跟运维学 Linux - 01

    跟运维学 Linux - 01 运维的诞生 运维工程师有很多叫法:系统运维.Linux 工程师.系统管理员... 网管可以说是运维工程师最早的雏形.在个人电脑未普及时,大家去网吧玩游戏. 玩家:&qu ...

  6. ENVI大气校正方法反演Landsat 7地表温度

    本文介绍基于ENVI软件,实现对Landsat 7遥感影像加以大气校正方法的地表温度反演操作. 目录 1 图像前期处理与本文理论部分 2 实际操作 2.1 植被覆盖度计算 2.2 地表比辐射率计算 2 ...

  7. java反序列化与反序列化

    java反序列化漏洞 JAVA反序列化漏洞是由于开发者重写了readObject方法,该readObject方法方法调用了别的方法,最终执行到了例如Transfrom方法的危险方法 java序列化过程 ...

  8. kafka分区分配策略

    前言 现有主流消息中间件都是生产者-消费者模型,主要角色都是:Producer -> Broker -> Consumer,上手起来非常简单,但仍有需要知识点需要我们关注,才能避免一些错误 ...

  9. Linux 文件系统的设计

    一 硬盘的最小存储单元是扇区,扇区大小为512B 文件系统将硬盘划分为固定大小的块(block),最常见的块大小为4KB 块是文件系统读写硬盘的最小单位 二 文件系统设计面临的基本问题: 用户怎么找到 ...

  10. 2021-7-29 MySql进阶

    Alter的使用: 列的增加和删减 alter table users add user_name VARCHAR(100);#添加一列在末尾 SELECT * from users; alter t ...