TOBO
然而并不会做。
最后就照着题解码了一遍/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的更多相关文章
- SP4546 ANARC08A - Tobo or not Tobo IDA*
题意:
- 【WC2013】糖果公园
Candyland 有一座糖果公园,公园里不仅有美丽的风景.好玩的游乐项目,还有许多免费糖果的发放点,这引来了许多贪吃的小朋友来糖果公园玩. 糖果公园的结构十分奇特,它由 nn 个游览点构成,每个游览 ...
- [Web 前端] SuperAgent中文使用文档
cp from : https://blog.csdn.net/gebitan505/article/details/58585846 superagent是nodejs里一个非常方便的客户端请求代理 ...
- MVC中Model BLL层Model模型互转
MVC中Model BLL层Model模型互转 一. 模型通常可以做2种:充血模型和失血模型,一般做法是模型就是模型,不具备方法来操作,只具有属性,这种叫做失血模型(可能不准确):具备对模型一定的简单 ...
- nodejs 框架 中文express 4.xxx中文API手册
介于最近express 中文文档比较难找的现状,特地找了一个,供大家学习思考 Express 4.x API express 翻译 api文档 中文 -- express() expre ...
- ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库
1.前提: 系统:ubuntu18.04 64位 数据库:mongodb GUI:Robo 3T 2018.3.0 描述: mongodb 安装在局域网内的ubuntu的机子上面, 在win 下 ...
- node.js express 中文参考手册
https://www.runoob.com/w3cnote/express-4-x-api.html 原文地址:https://www.zybuluo.com/bajian/note/444152 ...
随机推荐
- 5.2 基于ROP漏洞挖掘与利用
通常情况下栈溢出可能造成的后果有两种,一类是本地提权另一类则是远程执行任意命令,通常C/C++并没有提供智能化检查用户输入是否合法的功能,同时程序编写人员在编写代码时也很难始终检查栈是否会发生溢出,这 ...
- 在行情一般的情况下,就说说23级应届生如何找java工作
Java应届生找工作,不能单靠背面试题,更不能在简历中堆砌和找工作关系不大的校园实践经历,而是更要在面试中能证明自己的java相关商业项目经验.其实不少应届生Java求职者不是说没真实Java项目经验 ...
- zip文件结构
转starshine博客 一个zip文件由三个部分组成:压缩源文件数据区.压缩源文件目录区.压缩源文件目录结束标志 压缩源文件数据区: 50 4B 03 04:这是头文件标记(0x04034b50) ...
- Day-4 路由匹配源码
1. 请求来了会走WSGIHandler的call方法 convert_exception_to_response也是进行封装 真的handler是从下图定义 resolver = URLResolv ...
- [CF 1780B] GCD Partition
B. GCD Partition 题意 : 给一个长度为n的序列, 并将其分成连续的k块(k > 1), 得到序列b, 使得 \(gcd(b_{1}, b_{2}, b_{3}, ..., b_ ...
- PB从入坑到放弃(五)窗口使用技巧
PB应用程序就是由许多共同协作完成特定任务的窗口组成的集合. 窗口在应用程序的开发工作中占有很大的比重,是非常重要的一个 PB 对象 一.窗口类型 窗口类型 描述 Main ①可以覆盖其他窗口,也可以 ...
- http方式内网搭建CDH6.3.2与部分组件优化
Cloudera_Manager_6.3.2安装配置文档 1. 配置准备 Cloudera Manager (简称CM)用于管理CDH6集群,可进行节点安装.配置.服务配置等,提供Web窗口界面提高了 ...
- AWD-PWN流量监控与抄流量反打
RE手 在AWD中比较做牢,队伍里也没pwn手,在awd出现pwn靶机比较坐牢.之前都不知道pwn靶机可以抄流量反打. 参考pwn_waf:https://github.com/i0gan/pwn_w ...
- vue 实现 pdf 预览功能
1 技术背景 1.1 Vue.js 简介和特点 Vue.js 是一种用于构建用户界面的渐进式框架.它具有以下特点: 易学易用:Vue.js 的 API 设计简单直观,使得开发者可以快速上手. 响应式数 ...
- CVE-2022-42475-FortiGate-SSLVPN HeapOverflow 学习记录
前言 之前就想复现这个洞,不过因为环境的问题迟迟没有开工.巧在前一阵子有个师傅来找我讨论劫持 ssl结构体中函数指针时如何确定堆溢出的偏移,同时还他把搭建好了的环境发给了我,因此才有了此文. 如何劫持 ...