hdu 6171 Admiral 双向bfs+hash

淘宝x-mini-wua生成机制与硬件信息关联性深度解析 本文深度解析了淘宝x-mini-wua的生成机制与硬件信息的关联性,详细介绍了其作为设备指纹令牌的核心作用及技术实现细节。通过分析基础硬件层、环境特征层和行为特征层的数据采集,揭示了淘宝如何利用AES加密和分级加密策略防止破解,并探讨了其安全防护与对抗策略。 阅读详情


Admiral

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 153428/153428 K (Java/Others)
Total Submission(s): 206    Accepted Submission(s): 54


Problem Description
Suppose that you are an admiral of a famous naval troop. Our naval forces have got 21 battleships. There are 6 types of battleships.
First, we have got one flagship in which the admiral must be and it is denoted by number 0. Others are denoted by number from 1 to 5, each of them has 2, 3, 4, 5, 6 ships of its kind. So, we have got 21 battleships in total and we must take a giant battle against the enemy. Hence, the correct strategy of how to arrange each type of battleships is very important to us.
The shape of the battlefield is like the picture that is shown below.
To simplify the problem, we consider all battleships have the same rectangular shape.

Fortunately, we have already known the optimal state of battleships.
As you can see, the battlefield consists of 6 rows. And we have 6 types of battleship, so the optimal state is that all the battleships denoted by number i are located at the i-th row. Hence, each type of battleship corresponds to different color.
You are given the initial state of battlefield as input. You can change the state of battlefield by changing the position of flagship with adjacent battleship.
Two battleships are considered adjacent if and only if they are not in the same row and share parts of their edges. For example, if we denote the cell which is at i-th row and j-th position from the left as (i,j), then the cell (2,1) is adjacent to the cells (1,0), (1,1), (3,1), (3,2).
Your task is to change the position of the battleships minimum times so as to reach the optimal state.
Note: All the coordinates are 0-base indexed.
 

Input
The first line of input contains an integer T (1 <= T <= 10), the number of test cases. 
Each test case consists of 6 lines. The i-th line of each test case contains i integers, denoting the type of battleships at i-th row of battlefield, from left to right.
 

Output
For each test case, if you can’t reach the goal in no more than 20 moves, you must output “too difficult” in one line. Otherwise, you must output the answer in one line.
 

Sample Input
  
1 1 2 0 2 1 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5
 

Sample Output
  
3
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6181  6180  6179  6178  6177 
 

Statistic |  Submit |  Discuss |  Note
题意:给你一个塔,要你弄成第一行全是0的,第二行全是1,第三行全是2,以此类推,求最小步数,每一步只能把0移动到上方、左上方、下方、右下方。

思路:现场码了半天还是得10多s才能出答案。看了题解,双向bfs。。。感觉我又被套路了。在知道起点和终点的情况下,两边同时bfs能剪掉n多的枝,这个想一下还是想得通的。所以这题就把图hash成字符串(当然你也可以hash成数,6进制不会爆LL,只不过可能写起来不好写),然后两边同时bfs其中一方找到另一方时结束。可能会觉得我的代码风格有点奇怪,因为。。有一些是我叫队友码的,留接口给我用。下面给代码:

#pragma comment(linker, "/STACK:102400000,102400000") 
#include<iostream>  
#include<cmath>  
#include<queue>  
#include<cstdio>  
#include<queue>  
#include<algorithm>  
#include<cstring>  
#include<string>  
#include<utility>
#include<set>
#include<map>
#include<stack>
#include<vector>
#define maxn 200005
#define inf  0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long LL;
const double eps = 1e-5;
const int mod = 1e9+7;
int up[] = { -1, 0, -1, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, -1 };
int upleft[] = { -1, -1, 0, -1, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14 };
int down[] = { 1, 3, 4, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, -1, -1, -1, -1, -1, -1 };
int downright[] = { 2, 4, 5, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 20, -1, -1, -1, -1, -1, -1 };
map<string, int>m;
string ori = "011222333344444555555";
queue<string>q;
int solve(string next,string now,int nextpos,int pos){
	if (~nextpos){
		swap(next[pos], next[nextpos]);
		next[21] = nextpos / 10 + '0';
		next[22] = nextpos % 10 + '0';
		int cnt1 = m[next];
		int cnt2 = m[now];
		if (!cnt1){
			m[next] = m[now] + 1;
			q.push(next);
		}
		else if (cnt2 >= 20 && cnt1 <= 11 || (cnt2 <= 11 && cnt1 >= 20))
			return cnt1 + cnt2 - 20;
		swap(next[pos], next[nextpos]);
	}
	return 0;
}
int bfs(string x){
	while (!q.empty())
		q.pop();
	m.clear();
	int index;
	for (int i = 0; i < 21;i++)
		if (x[i] == '0'){
			index = i;
			break;
		}
	char s[5];
	s[0] = index / 10 + '0';
	s[1] = index % 10 + '0';
	s[2] = '\0';
	q.push(x += s);
	q.push("01122233334444455555500");
	m[x] = 20;
	m["01122233334444455555500"] = 1;
	while (!q.empty()){
		string now = q.front();
		q.pop();
		int num = m[now];
		if (num == 11 || num == 30)
			continue;
		int pos = (now[21] - '0') * 10 + now[22] - '0';
		int nextpos = up[pos];
		string next = now;
		int ans = solve(next, now, nextpos, pos);
		if (ans)
			return ans;
		nextpos = upleft[pos];
		ans = solve(next, now, nextpos, pos);
		if (ans)
			return ans;
		nextpos = down[pos];
		ans = solve(next, now, nextpos, pos);
		if (ans)
			return ans;
		nextpos = downright[pos];
		ans = solve(next, now, nextpos, pos);
		if (ans)
			return ans;
	}
	return -1;
}
string input()
{
	int cnt = 21;
	string s = "", t;
	while (cnt--) cin >> t, s += t;
	return s;
}
int main(){
	int t;
	scanf("%d", &t);
	while (t--){
		string now = input();
		if (now == ori){
			printf("0\n");
			continue;
		}
		int ans = bfs(now);
		if (~ans)
			printf("%d\n", ans);
		else
			printf("too difficult\n");
	}
}


1.DJI-payload SDK负载开发准备和硬件连接及运行示例代码 大疆psdk开发环境 阅读详情

相关推荐

Autosar开发实战:DaVinci Configurator Pro新建工程保姆级教程(附目录结构解析)

本文详细介绍了使用DaVinci Configurator Pro创建Autosar工程的完整流程,包括环境准备、工程配置、目录结构解析及常见问题排查。通过实战演示和深度解读,帮助开发者快速掌握工具使用技巧,优化工程管理,提升开发效率。特别适合需要理解Autosar开发中DaVinci Config工具链的工程师。

weixin_30872157的博客 456

hdu 6171

http://acm.hdu.edu.cn/showproblem.php?pid=6171 题意:有一个塔,这个塔一共有6层,第i-1层有i个数字,数字为i-1。 现在给你一个塔,要你恢复成原来的那样,但是你每次只能移动0这个数字,可移动的方向为左上,上,下,右下。 然后问你多少步可以到达 思路:如果简单的dfs的话,那么肯定会超时,那么我们考虑双向dfs,也就是正向反向都跑b...

A1823085974的博客 245

lattice Diamond Programmer程序下载

Lattice Diamond Programmer(支持Lattice FPGA与CPLD程序下载)

qq_44385725的博客 5171

HDU 6171 Admiral (DFS + 剪枝)

题意: 给出原始阵列 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 问对于给出的某种阵列,能否通过每步只移动 0 至(i - 1 , j)or ( i - 1 , j - 1)  or ( i + 1 ,  j ) or ( i + 1 , j  + 1 ) ,在20步之内移动到原始阵列。 思路: 考虑到只要求20步,直接搜索即可。 但

DT2131 638

避坑指南:Abaqus网格划分中90%用户会遇到的5个质量陷阱(附解决方案)

本文深入剖析Abaqus网格划分中90%用户会遇到的5个典型质量陷阱,包括单元扭曲、扫掠网格失败、尺寸梯度控制等,并提供工程级解决方案。通过Python脚本和虚拟拓扑等技巧,帮助用户提升网格质量,确保有限元分析结果的可靠性,适用于CAE工程师和仿真分析师。

weixin_29243279的博客 99

KEPServerEX中,别名映射(Alias Mapping)数据标签重命名机制

目录核心机制应用场景配置步骤技术特性与参考内容的差异KEPServerEX中,别名映射(Alias Mapping) 是一种数据标签重命名机制,主要用于简化复杂标签路径的调用或实现跨系统兼容。其核心逻辑和功能如下:路径抽象 将设备层级结构中的完整标签路径(如 Channel1.Device1.Tag1)映射为简短别名(如 TempSensor1),降低客户端调用的复杂度。动态绑定 别名与实际标签实时关联,数据更新和读写操作通过别名直接传递到底层物理标签,无需修改客户端配置。多对一映射支持多个别名指向

「东哥说MES」 专注于MES制造执行系统,为你拆解核心架构、功能模块及与ERP/PLC的集成逻辑。提供从入门到精通的系列干货、精选行业报告与实用工具,构建你的数字化知识体系,关注我,用实战经验照亮你的数字化之路。 1591

HDU 6171 Admiral(双向BFS+队列)题解

思路:最大步骤有20,直接BFS会超时。因为知道开始情况和结果所以可以用双向BFS,每个BFS规定最大步骤为10,这样相加肯定小于20。这里要保存每个状态搜索到的最小步骤,用Hash储存。当发现现有状态已经在另一路出现了,那么就输出两者相加的步骤和。代码:#include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;queue&gt;...

努力,奋斗 366

AI大模型探索之路-训练篇3:大语言模型全景解读

大规模语言模型(Large Language Models,LLM),也称大语言模型或大型语言模型,是一种由包含数百亿以上参数的深度神经网络构建的语言模型,通常使用自监督学习方法通过大量无标注文本进行训练。

寻道AI,探索AI无限可能! 6275

Admiral HDU - 6171

这题很像那道八数码的题目,可以把21个位置每个位置有6种数,那么总共有21的6次方种状态,那么是可以用一个longlong来表示状态,用set来判重的。但是这样还是不够快。我们可以利用A星算法来优化搜索过程A星算法的知识,A星算法中有两个重要的值,已走步数和到终点估计值,已走步数这个很容易得到,到终点的估计值这个我们可以估计每个不合法的点直接挪过去他该去的那一行该走的步数。估价值h(n)<=

qq965194745的博客 357

数据分析:蛋白质组的GO term的富集分析详解

在获取差异表达蛋白质的数据之后,依据蛋白质与基因的对应映射关系,开展GO(Gene Ontology)term的富集分析。通过这一分析流程,能够精准地识别出不同实验组中过表达基因所关联的显著富集的GO term通路。这些富集的GO term通路为后续的生物学研究提供了关键线索,有助于深入探究基因功能、揭示潜在的生物学机制,从而推动生物学发现的进程。

专注生信领域 1368

GPU服务器维修全流程:从检测到解锁

《GPU服务器维修维保全流程指南》摘要:本文系统介绍GPU服务器从检测到解锁的完整维修流程。检测环节包含物理检查(氧化层、散热、PCB板)和电子诊断(ECC报错率、电源波动等);核心维修技术涵盖PCB板修复(微孔镀铜、BGA返修)和芯片级维修(成功率78-92%);解锁验证阶段包括性能解锁(VBIOS重写)和72小时稳定性测试。文末提供故障速查表及维保建议,强调定期除尘可降低38%故障率,推荐环境粉尘浓度控制在≤0.3mg/m³。

2401_89353317的博客 889

hdu 6171 ida*

题意:一个数塔,类似八数码的样子。。 思路:正解双向搜索。。时间复杂度非常科学。。不过数据弱ida*搞了过去。。。。(大力出奇迹?) 代码; #include using namespace std; #define X first #define Y second #define PB push_back #define MP make_pair #define MEM(x,y) mems

zxl博客 438

鸢尾花分类预测

鸢尾花数据总用有150个样本,是一个典型的分类数据集,共有3个类别,分别是山鸢尾(Iris-setosa)、变色鸢尾(Iris-versicolor)和维吉尼亚鸢尾(Iris-virginica),每个样本的特征有4列sepal_length:萼片长度sepal_width:萼片宽度petal_length:花瓣长度petal_width:花瓣宽度这里我们定义了随机森林模型作为实例,来进行模型训练,之后我们会对其使用网格搜索找到最优的参数。

优快云 精品推荐 2188

【多校训练】hdu 6171 Admiral 双向bfs+hash

Problem Description Suppose that you are an admiral of a famous naval troop. Our naval forces have got 21 battleships. There are 6 types of battleships. First, we have got one flagship in which th

弱菜zc 600

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU 6171 Admiral [双向bfs+hash]

HDU 6171 Admiral [双向bfs+hash]

ACTerminate的博客 537

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

HDU 6171 Admiral(hash+双向bfs)

Description 给出一个六层的地图,从上到下第iii层有iii个块,以(i,j)(i,j)(i,j)表示第i+1i+1i+1层从左到右第j+1j+1j+1个块的坐标,一个块可以和与其相邻的块交换,两个块相邻当且仅当其某维坐标相同,第iii层块编号均为i−1i−1i-1,现在给出一个地图初始状态,要把编号为000的块移动到(0,0)(0,0)(0,0)处,问最少步数 Input 第一行...

ZSQ 384

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Hdu 6171 Admiral【双向Bfs+字符串哈希】

Admiral Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 153428/153428 K (Java/Others) Total Submission(s): 203    Accepted Submission(s): 52 Problem Description Suppose that you are an

mengxiang000000 981

2017多校联合第十场/HDU 6171 Admiral 双向bfs + 哈希

Admiral Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 153428/153428 K (Java/Others) Total Submission(s): 334    Accepted Submission(s): 105 Problem Description Suppose that you a

The_star_is_at的博客 858

HDU 6171 Admiral 双向搜索(meet in the middle) + 哈希

传送门:HDU6171 题意:给你一个高度为6的数塔,问最少多少步能走成如下状态。 每次只能将值为0的点与其左上方,上方,下方,右下方四个方向的一个点进行交换。  0  1 1  2 2 2  3 3 3 3  4 4 4 4 4  5 5 5 5 5 5 大于20步可以直接输出“too difficult” 思路:比赛的时候智障的想了一个多少小时的A* 和 IDA* ,还

WA是一笔财富 972

2017多校第10场 HDU 6171 Admiral 双向BFS或者A*搜索

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6171 题意: 给你一个高度为6的塔形数组,你每次只能将0与他上下相邻的某个数交换,问最少交换多少次可以变为初始状态,若需要的步数大于20,直接输出too difficult,初始状态为: 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 ...

aishangg437965的博客 134

HDU 6171 Admiral

HDU 6171 Admiral搜索,双向宽搜题意自己读题吧。不过有两点注意:每次只能把0数字和其他数字交换;每个数字的可交换范围是左上,正上,正下,右下。思路不会搜索啊。。。%%% 因为起始状态与终止状态都很明确,考虑双向宽搜。关于状态的表示与检查:作为6进制数哈希,用个map记录状态与达到该状态对应的步数。因为是双向搜索,所以开两个map记录。双向宽搜就是从初始状态搜,记录到map1;从终止状

P.H.S 479

2017 Multi-University Training Contest 10 1001 Admiral HDU 6171 (双向搜索 哈希)

题意: 给你一个高度为6的塔形数组,你每次只能将0与他上下相邻的某个数交换,问最少交换多少次可以变为初始状态,若需要的步数大于20,直接输出too difficult,初始状态为: 0  1 1  2 2 2  3 3 3 3  4 4 4 4 4  5 5 5 5 5 5 思路:因为最多走20步,当存搜索时间复杂度4^20, 所以我们可以分别从当前状态和初始状态进行双向

CillyB的博客 615

【双向bfs】2017多校训练十 HDU 6171 Admiral

【题意】 现在给出一个三角矩阵,如果0编号的在点(x,y)的话,可以和(x+1,y),(x-1,y),(x+1,y+1),(x-1,y-1)这些点进行交换。 我们每一次只能对0点和其他点进行交换。问最少步数,使得最终变成: 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 【思路】 【AC】 1 #include<...

weixin_30466039的博客 77

hdu6171 Admiral 双向宽搜

Admiral Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 153428/153428 K (Java/Others) Total Submission(s): 82    Accepted Submission(s): 19 Problem Description Suppose that you are

abutoto的博客 461

hdu6171 双向bfs

传送门 题意:给一个金字型塔的数列,第一行一个0,第二行两个1,。。。第6行6个5,现在金字塔数字打乱了,你只能移动0这个数字,只能向左上右上左下右下走,问在20步内能否回到原来状态。 一共21个数,每个有6种状态,没办法用一个 [21][6]维的数组记录状态,所以我们要用Hash记录状态,每个位置6种状态,那么最大是6^21的数字,long long可以存的下的。我们用bfs进行搜索,给两个起

猿的进化 560

hdu6171 双向搜索+hash

Suppose that you are an admiral of a famous naval troop. Our naval forces have got 21 battleships. There are 6 types of battleships. First, we have got one flagship in which the admiral must be and i

扬帆起航 675
上一篇: hdu 6166 Senior Pan 最短路
下一篇: 高斯消元模板
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值