uva 10085 The most distant state

直流耦合系统介绍 参考《SMA如何使用直流耦合技术实现更高效的光伏电站-白皮书》 阅读详情


此题就是状态搜索题;使用bfs来获得最远的那个状态,然后打印出来,中间记录一下父节点就可以了。


此题需要注意到的技巧:

1.使用数组代替栈

2.hash函数的使用,将每个状态用整数表示。

3.memcpy整块内存的复制,memcmp整块内存的比较。


//
//  main.cpp
//  uva10085 The Most Distant State
//
//  Created by XD on 15/8/4.
//  Copyright (c) 2015年 XD. All rights reserved.
//

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<vector>
#include <string.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstdio>
using namespace std ;

typedef int State[10];
const int maxstate = 10000000 ;
int fa[maxstate] ;
State st[maxstate]  , goal ;
int dist[maxstate] ;

const int dx[] = {-1,1,0,0} ;
const int dy[] = {0 ,0 ,-1 ,1} ;

const int hashsize = 1000003 ;
int head[hashsize] , mnext[maxstate] ;

int  ans ;
void init_lookup_table()
{
    memset(head, 0, sizeof(head)) ;
    memset(mnext, 0, sizeof(mnext)) ;
    memset(fa, 0, sizeof(fa)) ;
}
int Hash(State& s)
{
    int v = 0 ;
    for (int i = 0; i <9 ; i++) {
        v = v * 10  +  s[i] ;
    }
    return v % hashsize ;
}

int try_to_insert(int s)
{
    int h = Hash(st[s]) ;
    int u = head[h] ;
    while (u) {
        if (memcmp(st[u],st[s], sizeof(st[s])  - sizeof(int)) == 0 ) {
            return 0 ;
        }
        u = mnext[u] ;
    }
    mnext[s] = head[h] ;
    head[h] = s ;
    return 1 ;
    
    
}


int  bfs()
{
    init_lookup_table() ;
    int front = 1  , rear = 2  ;
    while (front < rear) {
        State& s = st[front] ;
        if (front + 1  ==rear) {
            ans =front ;
        }
        int z ;
        for (int i = 0; i < 9 ; i++) {
            if (s[i] == 0 ) {
                z = i ;
                break ;
            }
        }
        int x = z / 3  ; int y = z%3 ;
        for (int i = 0 ; i< 4; i++) {
            int newx = x + dx[i] ;
            int newy = y + dy[i] ;
            int newz = newx * 3 + newy ;
            if (newx >= 0 && newy>= 0&& newx <3&& newy<3) {
                State& t = st[rear] ;
                memcpy(&t, &s, sizeof(s)) ;
                t[newz] = s[z]  ;
                t[z] = s[newz] ;
                t[9] = i ;
                
                dist[rear] = dist[front] + 1;
                if (try_to_insert(rear)) {
                    fa[rear] = front ;
                    rear++ ;
                }
            }
        }
        front++  ;
    }
    
    return  ans ;
}


int main(int argc, const char * argv[]) {
    int j = 0;
    int casenum ;
    scanf("%d" ,&casenum) ;
    while (casenum--) {
        printf("Puzzle #%d\n" , ++j) ;
        
        for (int i = 0 ; i < 9 ; i++) {
            scanf("%d" , &st[1][i]) ;
        }
        bfs() ;
        for (int i = 0; i  < 9; i++) {
            printf("%d " ,st[ans][i]) ;
            if (i % 3 == 2) {
                printf("\n") ;
            }
        }
        vector<char> anspath  ;
        anspath.clear() ;
        while (ans != 1 ) {
            char direct ;
            switch (st[ans][9]) {
                case 0:
                    direct = 'U' ;
                    break;
                case 1:
                    direct = 'D' ;
                    break ;
                case 2:
                    direct = 'L' ;
                    break ;
                case 3  :
                    direct = 'R' ;
                    break ;
                default:
                    break;
            }
            anspath.push_back(direct) ;
            ans = fa[ans] ;
        }
        int len =(int ) anspath.size() ;
        for (int i = len-1 ; i >= 0; i--) {
            printf("%c" , anspath[i]) ;
        }
        cout << endl <<endl ;
    }
    
    return 0;
}


终端运行脚本报: 因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fw link/?LinkID=135170 中的 about_Execution_ PowerShell 执行策略是一种安全机制,用于控制哪些脚本可以在系统上运行。默认情况下,Windows 系统会设置较为严格的执行策略,以防止恶意脚本的执行。执行策略有以下几种常见级别:Restricted(限制):不允许运行任何脚本。AllSigned(全部签名):仅允许运行经过数字签名的脚本。RemoteSigned(远程签名):允许运行本地脚本,但远程下载的脚本需要数字签名。Unrestricted(无限制):允许运行所有脚本,但会警告未签名的脚本。 阅读详情

相关推荐

【BigWorld 游戏服务器引擎】Cell 架构设计介绍,及Java实现方案的探索

横向扩展(Scalability):通过动态增减CellApp和BaseApp的数量,可以轻松应对玩家人数的变化。世界可以做得非常大,只需增加更多的 Cell。负载分离(Load Separation):将不同性质的负载分离,避免了单一进程瓶颈。CPU 密集型的实时计算(CellApp)和 I/O 密集型的数据操作(BaseApp)互不影响。高效的视野管理(AOI):每个 Cell 只关心自己区域内和边界上的实体,大大降低了计算复杂度。容错性:某个CellApp。

代码时光 1205

uva 10085 The most distant state

没有什么好的办法,广搜遍历状态树,最后一个状态就是答案,运行都3s多了居然还可以过,这道题好像没什么意义啊,没看出这道题的价值在哪。 #include #include #include #include using namespace std; struct state { int blank_i, blank_j; char m[4][4]; int step; cha

皓首不倦 不负少年 794

ZYNQ RFSoC 的DAC如何做到从 0到Fs频段 信号输出

之前一直没太了解 RFSoC 的DAC如何输出在 Fs/2 到 Fs 频率范围内的信号,例如 ZCU216中的 ZU49DR,其RF-DAC最大采样率是 9.85GSPS,如果想输出的信号中心频率在5.8G,它是如何有效输出在第二奈奎斯特区域范围的信号的。

weixin_44630490的博客 1552

UVA 10085 The most distant state

分析八数码,规则只能在3×3的棋盘里移动棋子,棋子只能移到空位。 本题需要求的是在移动的棋盘不重复的情况下可以移动的方式以及棋面。这是一题隐式图搜索。 给定一个棋面状态,向空白处移动,可以视为空白处向四个方向移动。这样以空白处为研究对象,搜路,直到搜遍整个棋盘。可以发现,相对这题更合适bfs,广度优先搜索而不是深度优先搜索,因为题目所需要的只是最后一个可达状态。下面简要的提出思路。从队列中取出一

已注销的博客 482

清理异常值(MAD:绝对中位差)

清理异常数据: 中位数绝对偏差(MAD):用来描述单变量样本在定量数据中可变的一种标准 在统计学中,绝对中位差是刻画一元数据样本变化的一个鲁棒度量。由公式可以看出,其求解还算简单,给定一个数据样本集,首先求其中位数,然后求原始数据减去中位数的绝对值从而形成一个新的数据样本,再求新的数据样本的中位数即为绝对中位差。比如说有一个数据样本集X={2 3 8 7 9 6 4},这时候数据的中位数是6,原...

spider_man 1万+

MGC3130 3D手势识别传感器原理图设计,已量产(交互传感器)

最近在落地一款互动艺术装置的控制模块,选了 Microchip 的 MGC3130 做核心 —— 这颗芯片算是 GestIC® 近场传感技术的 “熟面孔” 了,把 3D 手势识别、运动跟踪的信号处理都集成在一颗芯片里,0-10cm 的检测距离刚好适配桌面级互动场景,挥挥手就能控设备的体验,放在艺术装置里确实很出效果。今天扒一下实际跑通的原理图,聊聊每个模块的设计思路。

不脱发的程序猿 371

uva 10085 The most distant state

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1026题目描述:The 8-puzzle is a square tray in which eight square tiles are placed. The remaining ninth sq

心之所向,无惧无悔! 731

恒玄BES调试笔记-BES2500如何OTA升级ANC和通透参数

前期量产软件anc参数主要是通过anc工具写入flash中,或者anc total gain通过美格信设备校准写入,对于量产后如果想要更新anc参数,如通透模式参数,则无法更新。 这个时候需要通过OTA升级软件,把相关anc参数内置到软件中,从flash中读取total gain。 1、更新强弱降噪和通透参数,由于涉及到个人参数就不列出来了,主要是改动以下相关参数。 extern struct_anc_cfg * anc_coef_list_50p7k[ANC_COEF_...

leezs的博客 2224

uva 10085-The most distant state

//死的暴力搜索,解答树最深层即解答,所以直接搜索到最深处,最后一个节点即答案,当然效率也不好,想不到啥好方法,实现上和上面的隐式图搜索是差不多的 #include #include //using namespace std; #define MAX_SIZE 1000000 #define MAX_STATE 362880 #define L 0 #define R 1 #define

无题 801

具身智能(26):RDK S100的LeRobot或Agile X piper机械臂控制模型

本文档详细介绍了基于ROS2的机器人控制模型架构与标定数据联动机制。核心采用"感知-规划-控制"闭环流程,通过激光雷达、相机和IMU的融合数据实现厘米级定位(≤1cm)。文档包含两大控制模型配置:1)RDKLeRobot模型,重点说明PID参数调节和标定文件路径设置;2)AgileXPiper模型,强调驱动安装与外部标定文件集成。针对常见问题提供解决方案,如控制指令无响应需验证标定路径,运动偏差过大需重新标定等。最后给出批量部署方案,通过复制基准配置文件实现多机器人快速配置,要求定位偏差

码农17年的博客 179

【RT-DETR涨点改进】全网独家-特征融合改进篇 | AAAI 2025 顶会| 高效涨点,RT-DETR利用CDFA对比度特征聚合模块,适用于目标检查(全网独家创新)

本文提出了一种基于CDFA模块的多级特征融合优化RT-DETR模型,用于解决医学图像分割中的软边界模糊、小目标和共现现象等问题。CDFA模块通过对比度特征聚合、局部特征增强和多级注意力机制,有效提升模型性能。研究提供了三种改进方案(rtdetr-r18/y50/l-CDFA),并在多个医学数据集上验证了其有效性。核心创新包括语义信息解耦、对比驱动特征融合和尺寸感知解码器。实验结果表明,该方法在分割精度和鲁棒性方面达到SOTA水平。

Ai缝合怪、助力小伙伴高效发论文 510

uva10085 - The most distant state

bfs  +  哈希技术,,, 超经典,超高效代码::: #include #include #define MAX 1000000 int ans, st[MAX][9], head[MAX], next[MAX], posi[MAX], fa[MAX], path[MAX]; int dx[4] = {-1,1,0,0}, dy[4] = {0,0,-1,1}; char dir[

稻草人 617

【OpenClaw企业级智能体实战】第27篇:Skill生态运营——企业私有Skill商店的搭建与审核机制

2026年ClawHavoc供应链攻击事件曝光超1200个恶意Skill渗透公共技能市场,工信部明确要求企业审慎使用第三方技能包并严格审查代码。本文基于真实安全事件与行业实践,完整讲解企业私有Skill商店从0到1搭建方案,覆盖小团队极简GitLab私有仓库、中大型企业Nacos 3.2私有Registry两种主流架构,配套企业级安全审核四步法、静态代码扫描规则、CI/CD自动化审计、数字签名校验与版本生命周期管理。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 501

UVa 10085 - The Most Distant State

传送门UVa 10085 - The Most Distant State

一只冰熊 910

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

UVA 10085 - The most distant state

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=110&page=show_problem&problem=1026 类型: 隐式图搜索 原题: The 8-puzzle is a square tray in which eight square t

D_Double's Journey 1583

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

uva:10085 - The most distant state

10085 - The most distant state 题目大意:就和八码数问题类似,只是题目没有给最终的状态,要求你自己写出最终的状态,并且给出最短的路径。 解题思路:和八码数的解题思路是相同的,只是不给最终的状态,而是让它自己去bfs()直到最后已经不能在走的地步(再走下去就会重复的情况),这里的判重用了哈希判重。 然后就是存储路径问题:开了一个数组dis【】用来存

882

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

UVA - 10085 The most distant state

题目大意:求所给图达到最远状态的时候,移动最少次的移动顺序。 解题思路:bfs+判重。定义一个结构体存放当前图,空白位置的坐标,移动次数即移动到该图的步骤。每改变一次就判断,然后放入队列。 依旧是参考别人题解的咸鱼。#include<iostream> #include<cstdio> #include<cmath> #include<string.h> #include<stdlib.h>

life kicks in right now 314

uva 10085 The most distant state(BFS + HASH)

uva 10085 The most distant state The 8-puzzle is a square tray in which eight square tiles are placed. The remaining ninth square is uncovered. Each tile has a number on it. A tile that is

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 687

uva 10085 - The most distant state

Problem A The Most Distant State Input: standard input Output: standard output   The 8-puzzle is a square tray in which eight square tiles are placed. The remaining ninth square is uncovered. E

uva code 1275

UVa10085 - The most distant state

#include #include #define N 3 #define MAX 3000000 #define HASHSIZE 1000003 #define DIRSIZE 100 typedef struct node { int x, y, step; int a[N][N]; char dir[DIRSIZE]; }node; node queue[M

多看多听多总结 818

uva10085 The most distant state(BFS)

Problem A The Most Distant State Input: standard input Output: standard output   The 8-puzzle is a square tray in which eight square tiles are placed. The remaining ninth square is uncovered. Eac

WONDERZY 925

UVa 10085 - The most distant state

八数码问题的变形,bfs+哈希,打印路径时花了点时间,用哈希表next数组的原理进行回退就可以将问题解决。 代码如下: #include #include #include #include #include #include using namespace std; const int MAXSIZE = 1000003; const int dx[4] = {-1, 1, 0

GooMaple 924

uva10085 The most distant state

基本功不够导致浪费了很多时间啊。。。 开始没想清楚,傻乎乎的用dfs结果运行

cgjiayou 445

UVa:10085 The most distant state

八数码问题变形。 还是bfs+判重,这里我尝试了set来判重,将9个格映射成一个9位整数。最后跑了3s多,还是很慢。。   #include #include #include #include #include #include #include using namespace std; int M[5][2]= {{1,0},{-1,0},{0,1},{0,-1}}; struct St

Fighting 693
上一篇: uva 10422 Knights in FEN
下一篇: uva 11882 Biggest Number
LuckyqXd
博客等级 码龄12年 2粉丝 86原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值