UVA - 10047 The Monocycle

对接萤石平台调用播放 萤石api 管理 · 萤石开放平台API文档 httpclient pom <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> package com.ruoyi... 阅读详情

从刘汝佳训练指南上看到的一道题,看了解释之后发现是一道最短路问题,(x,y,d,c)表示位于(x,y)点面向为d,颜色为c的状态,然后每个状态有左转,右转,前进3个转移方式也就对应三条边,然后建图求最短路就可以了。

代码:

  1 #include <iostream>
  2 #include <sstream>
  3 #include <cstdio>
  4 #include <climits>
  5 #include <cstring>
  6 #include <cstdlib>
  7 #include <string>
  8 #include <map>
  9 #include <cmath>
 10 #include <vector>
 11 #include <queue>
 12 #include <algorithm>
 13 #define esp 1e-6
 14 #define pb push_back
 15 #define in  freopen("in.txt", "r", stdin);
 16 #define out freopen("out.txt", "w", stdout);
 17 #define print(a) printf("%d\n",(a));
 18 #define bug puts("********))))))");
 19 #define stop  system("pause");
 20 #define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
 21 #define inf 0x0f0f0f0f
 22 using namespace std;
 23 typedef long long  LL;
 24 typedef vector<int> VI;
 25 typedef pair<int, int> pii;
 26 typedef vector<pii,int> VII;
 27 typedef vector<int>:: iterator IT;
 28 const int maxn = 100000;
 29 const int maxm = 60*25*25+100;
 30 struct EDGE
 31 {
 32     int i, c;
 33     EDGE *next, *ani;
 34 } *Edge[maxn], E[maxm];
 35 int cnt = 0;
 36 int src;
 37 int R, C;
 38 int node[30][30][10][10];
 39 int dx[] = {-1, 0, 1, 0};
 40 int dy[] = {0, 1, 0, -1};
 41 int dis[maxn], inq[maxn];
 42 char maze[30][30];
 43 void add(int i, int j, int c, EDGE &e1)
 44 {
 45     e1.i = j, e1.next = Edge[i], e1.c = c, Edge[i] = &e1;
 46     cnt++;
 47 }
 48 void init(void)
 49 {
 50     cnt = 0;
 51     memset(Edge, 0, sizeof(Edge));
 52 }
 53 void spfa(int ss)
 54 {
 55     memset(inq, 0, sizeof(inq));
 56     memset(dis, 0x0f, sizeof(dis));
 57     dis[ss] = 0;
 58     queue<int> q;
 59     inq[ss] = 1;
 60     q.push(ss);
 61     while(!q.empty())
 62     {
 63         int u = q.front(), v;
 64         q.pop();
 65         inq[u] = 0;
 66         for(EDGE *p = Edge[u]; p; p = p->next)
 67         {
 68 //            print(p->i)
 69             if(dis[v = p->i] > dis[u] + p->c)
 70                 if(dis[v] = dis[u] + p->c, !inq[v])
 71                     inq[v] = 1, q.push(v);
 72         }
 73     }
 74 }
 75 void build_graph()
 76 {
 77     for(int i = 0; i < R; i++)
 78         for(int j = 0; j < C; j++)
 79             if(maze[i][j] == '.')
 80                 for(int k = 0; k < 4; k++)
 81                     for(int l = 0; l < 5; l++)
 82                     {
 83                         int u = node[i][j][k][l], v;
 84                         v = node[i][j][(k - 1 + 4)%4][l];
 85                         add(u, v, 1, E[cnt]);
 86                         v = node[i][j][(k + 1)%4][l];
 87                         add(u, v, 1, E[cnt]);
 88                         int ii = i + dx[k];
 89                         int jj = j + dy[k];
 90                         if(ii >= 0 && ii < R && jj >= 0 && jj < C && maze[ii][jj] == '.')
 91                         {
 92                             v = node[ii][jj][k][(l+1)%5];
 93                             add(u, v, 1, E[cnt]);
 94                         }
 95                     }
 96 }
 97 int main(void)
 98 {
 99     int t = 1;
100     for(int i = 0; i < 30; i++)
101         for(int j = 0; j < 30; j++)
102             for(int k = 0; k < 10; k++)
103                 for(int l = 0; l < 10; l++)
104                     node[i][j][k][l] = i*(30*10*10)+j*(10*10)+k*10+l;
105     while(scanf("%d%d", &R, &C), R||C)
106     {
107         init();
108         int sx, sy, tx, ty;
109         for(int i = 0; i < R; i++)
110         {
111             scanf("%s", maze[i]);
112             for(int j = 0; j < C; j++)
113                 if(maze[i][j] == 'S')
114                 {
115                     sx = i;
116                     sy = j;
117                     maze[i][j] = '.';
118                 }
119                 else if(maze[i][j] == 'T')
120                 {
121                     tx = i;
122                     ty = j;
123                     maze[i][j] = '.';
124                 }
125         }
126         build_graph();
127         src = node[sx][sy][0][0];
128         spfa(src);
129         int ans = inf;
130         for(int k = 0; k < 4; k++)
131         {
132             int end = node[tx][ty][k][0];
133             ans = min(ans, dis[end]);
134         }
135         if(t - 1)
136             puts("");
137         printf("Case #%d\n", t);
138         t++;
139         if(ans == inf)
140             puts("destination not reachable");
141         else printf("minimum time = %d sec\n", ans);
142     }
143     return 0;
144 }
View Code

 

下面是汝佳神牛的代码,不禁感叹真是一目了然啊。、

 1 #include <iostream>
 2 #include <sstream>
 3 #include <cstdio>
 4 #include <climits>
 5 #include <cstring>
 6 #include <cstdlib>
 7 #include <string>
 8 #include <map>
 9 #include <cmath>
10 #include <vector>
11 #include <queue>
12 #include <algorithm>
13 #define esp 1e-6
14 #define pb push_back
15 #define in  freopen("in.txt", "r", stdin);
16 #define out freopen("out.txt", "w", stdout);
17 #define print(a) printf("%d\n",(a));
18 #define bug puts("********))))))");
19 #define stop  system("pause");
20 #define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
21 #define inf 0x0f0f0f0f
22 using namespace std;
23 typedef long long  LL;
24 typedef vector<int> VI;
25 typedef pair<int, int> pii;
26 typedef vector<pii,int> VII;
27 typedef vector<int>:: iterator IT;
28 const int maxr = 25 + 5;
29 const int maxc = 25 + 5;
30 struct State
31 {
32     int r, c, dir, color;
33     State(int r, int c, int dir, int color): r(r), c(c), dir(dir), color(color) {}
34 };
35 int R, C, ans;
36 int d[maxr][maxc][4][5], vis[maxr][maxc][4][5];
37 char maze[maxr][maxc];
38 int sr, sc, tr, tc;
39 int dr[] = {-1, 0, 1, 0};
40 int dc[] = {0, 1, 0, -1};
41 queue<State> q;
42 void update(int r, int c, int dir, int color, int v)
43 {
44     if(r <0 || r >= R || c < 0 || c >= C || maze[r][c] != '.' || vis[r][c][dir][color]) return;
45     vis[r][c][dir][color] = 1;
46     d[r][c][dir][color] = v;
47     q.push(State(r, c, dir, color));
48     if(r == tr && c == tc && color == 0)
49         ans = min(ans, v);
50 }
51 void bfs(State st)
52 {
53     vis[st.r][st.c][st.dir][st.color] = 1;
54     d[st.r][st.c][st.dir][st.color] = 0;
55     q.push(st);
56     while(!q.empty())
57     {
58         State st = q.front();
59         q.pop();
60         int v = d[st.r][st.c][st.dir][st.color] + 1;
61         update(st.r, st.c, (st.dir+3)%4, st.color, v);
62         update(st.r+dr[st.dir], st.c+dc[st.dir], st.dir, (st.color+1)%5, v);
63         update(st.r, st.c, (st.dir+1)%4, st.color, v);
64     }
65 }
66 int main(void)
67 {
68     
69     int t = 1;
70     while(scanf("%d%d", &R, &C), C||R)
71     {
72         if(t - 1)
73             puts("");
74         memset(vis, 0, sizeof(vis));
75         for(int i = 0; i < R; i++)
76         {
77             scanf("%s", maze[i]);
78             for(int j = 0; j < C; j++)
79                 if(maze[i][j] == 'S')
80                     sr = i, sc = j;
81                 else if(maze[i][j] == 'T')
82                     tr = i, tc = j;
83         }
84         ans = inf;
85         maze[sr][sc] = maze[tr][tc] = '.';
86         bfs(State(sr, sc, 0, 0));
87         printf("Case #%d\n", t);
88         if(ans != inf)
89             printf("minimum time = %d sec\n", ans);
90         else puts("destination not reachable");
91         t++;
92     }
93     return 0;
94 }
View Code

 

jre9下载 jdk9 (Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】 立即下载

相关推荐

VSCode里玩转AvaloniaUI:手把手教你搭建跨平台桌面应用开发环境(附.NET 7配置避坑)

本文详细介绍了如何在VSCode中搭建AvaloniaUI跨平台桌面应用开发环境,包括.NET 7配置避坑指南。从环境准备、项目创建到调试优化,手把手教你利用VSCode和Avalonia实现高效开发,特别解决了.NET 7依赖等常见问题,助力开发者快速上手跨平台应用开发。

weixin_28826545的博客 577

UVA10047 UVALive2035 The Monocycle【BFS】

A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with five different colors as shown in the figure: &nbsp;&nbsp;&nb...

海岛Blog 777

SAP FICO 资产会计AA后台配置 (上)

输入折旧表“CZ11”如有外币计价的资产,则需指定外币计价的资产折旧范围,以及规则。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。新增资产类型:Z101 固定资产-房屋及建筑物新增资产类型:Z301 固定资产-房屋及建筑物。

ghgxm520的博客 1762

uva 10047 The Monocycle (BFS)

uva 10047 The Monocycle A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with five different colors as

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

基于verilog的16QAM调制

思路1:正交调幅法——实现16QAM调制,可以理解为时相位相差90度的两个正弦波的4PAM叠加。 4比特输入经过2->4进制转化得到两路2比特输入,然后分别经过4PAM后叠加所得输出即为16QAM调制结果。 具体程序稍后编写。 思路2:复合相移法——可以借助前面编写的QPSK,相当于两路幅度不同的QPSK的叠加,比如幅度分别取1和3 。 思路1正交调幅法的设计方案: 两正弦波相位差...

weixin_30725467的博客 2929

MATLAB 论文复现——基于虚拟储能的电动汽车充放电调度策略及激励评价

文章基于虚拟储能聚合体仿真模型优化电动汽车充放电调度,并采用复合权重评价电动汽车的充电激励。根据电动汽车灵活性和系统稳定性衡量其贡献大小,并通过模糊推理系统模拟用户的充电意愿,实现对电动汽车充电的引导和优化。[1]陈朔,胡昊,方慧敏,等.基于虚拟储能的电动汽车充放电调度策略及激励评价[J/OL].系统仿真学报,1-12[2024-07-24].https://doi.org/10.16182/j.issn1004731x.joss.23-1316.基于虚拟储能的电动汽车充放电调度策略及激励评价。

sjr1478的博客 363

UVa10047 The Monocycle

UVa10047 The Monocycle   链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19491   (以上摘自http://blog.youkuaiyun.com/shuangde800/article/details/7686003)   【思路】   BFS。   以节点位置(x,y)方向dir

hahalidaxin的专栏 283

计算机视觉-全景图像拼接中的特征匹配与优化策略

本文深入探讨了计算机视觉中全景图像拼接的核心技术,重点解析了特征匹配后的关键优化策略。通过SIFT特征提取、RANSAC算法剔除误匹配,并结合APAP算法应对视差与鬼影问题,详细阐述了从基础对齐到无缝融合的完整流程,为开发者实现高质量全景拼接提供了实用指南。

weixin_29039773的博客 361

UVA 10047 The Monocycle

UVA-10047题意:独轮车有5个颜色,每一秒独轮车可以向前移动(面朝的方向移动一格)或者原地转90度(左右都行)。初始是绿色朝下,面向北面,初始位置为S。要求用多少秒能到达T并且还是绿色朝下。 解题思路:BFS,只不过除了常规的坐标XY之外多了方向D和颜色C。vis[x][y][d][c]。操作就是向前走一格以及左右旋转。假设初始5个颜色为01234,下一个颜色就是(c+1)%5。方向预设好移

QzNarsh的博客 346

STM32F407硬件IIC驱动OLED避坑实录:从‘不显示’到‘稳定刷屏’的完整调试过程

本文详细记录了使用STM32F407硬件IIC驱动OLED屏幕的完整调试过程,从初始的‘不显示’问题到最终实现‘稳定刷屏’。文章涵盖了硬件接线、I2C外设配置、常见问题排查及性能优化技巧,特别针对STM32标准库开发中的难点提供了实用解决方案,是嵌入式开发者驱动OLED屏幕的实用指南。

weixin_30315723的博客 303

Blender入门教程-3D视图界面介绍

3D视图用于与3D场景交互,可用于各种目的,例如建模、动画、纹理绘制等。在关闭 启动画面 后,启动场景会显示在3D视口中(如果没有加载其他blend文件)。01 标题栏标题栏包含了基于当前 模式 的各种菜单和控制。

weixin_52345129的博客 2287

uva10047 - The Monocycle

uva10047 - The Monocycle 一个让我想死的题目,怎么想都没有想到这个题要用广度优先搜索。而且,题目说了,能左转走,能右转走,不能倒着走。妹的,最后一想,我转2次方向,就面向背面了,相当于“往后转”。而且,“走”,和“转”要分开。 1、输入地图,初始化相关存储变量。 2、广度优先搜索,注意状态记录,“走”,和“转”要分开。 3、输出结果,判断搜索情况,搜索是否成

花花的笔记 876

Claude Code(8):使用 skill-creator 打造属于测试人员的 Skills

本文介绍了如何使用Claude Code的skill-creator工具快速创建测试相关的Skills。skill-creator是一个专门用于创建新Skills的Skill,相比手动创建更高效。文章详细演示了安装skill-creator的步骤,并通过创建"测试计划编写助手"的实战案例,展示了如何通过对话方式定义Skill名称、触发条件和功能需求。skill-creator会自动生成完整的SKILL.md文件和目录结构,用户只需确认即可完成Skill创建。

blues_C的博客 525

UVA - 10047 The Monocycle(bfs)

UVA - 10047 The Monocycle(bfs) A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with five different colors as shown ...

weixin_43179892的博客 309

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ssm框架搭建

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

uva 10047 - The Monocycle

Problem A: The Monocycle  A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with five different colors as

uva code 1504

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

uva 10047 The Monocycle

#include #include #include #include #include using namespace std; #define N 30 char Map[N][N]; int n,m; int dx[4]={-1,0,1,0}; int dy[4]={0,1,0,-1}; struct node{ int x,y; int steps; int dir; int c

DieOrThink 685

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

UVa 10047 - The Monocycle

求从起始点能到达终点的并且颜色与初始状态相同的最短路径 bfs求最短i路问题,只不过需要记录坐标、颜色、方向三种状态 #include #include typedef struct { int x; int y; int cl; int di; int t; }node; node q[12550]; char map[30][30]; i

DC的ACM奋斗史 917

uva 10047 The Monocycle

这道题目消耗了我不少时间,通过这道题目的解答,我对于广度优先搜索的理解更加深刻了,在BFS里面,每一次对于下一步状态的拓展并不是像以前的简单BFS一样仅仅局限于在位置上的更新,而应该扩展到下一步所有可能到达的状态,例如这道题里面状态由四个维度上的值决定:X坐标,Y坐标,方向,颜色,所以应该用一个四维数组来维护BFS的访问矩阵,并且我深刻理解到,每一次状态的拓展的粒度必须要分到最细,因为一开始的时候

皓首不倦 不负少年 508

UVA 10047 - The Monocycle(BFS)

题目链接:点击打开链接 题意:从起点到终点,每秒可以选择前进、向左、向右转, 每前进一格轮子转到下一个颜色, 一共5中颜色, 开始的时候绿色接触地面,朝北, 要求最后也绿色接触地面,求能否到达目标点以及最短时间。 思路:和普通BFS相比,多了两个附加条件,所以要将状态表示全面,也要对应加两维。 水题。 细节参见代码: #include #include #include #include

AC_Arthur的专栏 2184

The Monocycle UVA - 10047

题目链接:https://vjudge.net/problem/UVA-10047 其实蓝书上写的挺好的,用四个状态,xy坐标,朝向,颜色作为一个节点。 然后就easy了 JAVA代码 import java.util.*; import java.io.*; import java.math.*; public class Main { final static int inf=1&...

King8611的博客 333

Uva 10047 The Monocycle

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=988 搜索题目。 只不过把(x,y,d,c)作为一个结点。每个节点出发最多有三条边,分别对应前进、左转、右转。 #include #include #include #include

2537

UVA 10047 - The Monocycle

题目如下:  Problem A: The Monocycle  A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with fiv

hexiecs的技术专栏 1252

UVA10047 The Monocycle BFS

用一个四维数组判重即可,其他部分和一般的BFS一样,每次扩展节点的时候,不能像其他题目一样四个方向扩展,因为题目中的状态涉及到方向,所以每次扩展的时候分为三种情况,左转,右转,前进一格。 The Monocycle Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %

843

Uva10047 The Monocycle

原题链接:https://vjudge.net/problem/UVA-10047 绞尽脑汁的图论题,虽然只是bfs但是要求到达的最小时间以及符合到达终点的条件还是需要思考一番。 用优先队列保证到达时间最小,每一个方块的访问方式由进入的方向以及轮子的颜色划分。 #include #define INF 0x3f3f3f3f using namespace std; int n,m; int

DlPF_C的博客 420

UVA 10047 The Monocycle

白书上图论例题2 题目大意是 M*N个格子 #不能走 S是起点 T是终点 上北下南左西右东 一开始在S,朝向北, 在每一个格子 可以左转90度 或者右转90度 或者朝向走1格 问从起点到终点 计算重复格子 走5的整数倍个格子到终点 不限制最后朝向 最短时间是多少 就像书上讲的那样 每个点 拆成20个点 (x,y,color,head) 分别表示该点的坐标,走到该点 走过

弱者要战斗 520

The Monocycle UVA10047

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #includ

霁月难逢 彩云易散 786
上一篇: UVA 10651 Pebble Solitaire 状态压缩dp
下一篇: UVALive - 4255 Guess
rootial
博客等级 码龄15年 2粉丝 93原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值