9161. VOYAGER

限制条件

时间限制: 1 秒, 内存限制: 256 兆

题目描述

The Voyager 1 space probe (not to be confused with the Intrepid-class starship) was launched a long
time ago, in 1977, and is currently on the verge of leaving our Solar System. As it travels further
through space, it has been programmed to leave a radio signal message in any star system it stumbles
upon, to mark the probe's path for as long as possible.
Let us assume that a star system can be represented by a rectangular grid with N rows and M
columns, dividing the space into N by M equal cells. Each cell can contain a single planet, black
hole, or be empty. The probe broadcasts the signal from a pre-determined empty cell, in one of the
four axis-aligned directions (U?up, R?right, D?down, L?left).

Upon being broadcast, the signal propagates in a straight line along the same row/column until it
reaches a planet, where it is deflected by 90 degrees in another direction. There are two kinds of
planets, which we will denote by / and \ The deflection rules are shown in the image below:
The signal permanently leaves the system upon either entring a cell containing a black hole, or
propagating outside the edges of the rectangular grid. It is also known that the signal needs one second
to propagate from the current cell to a neighbouring one.


Write a program to determine the direction in which the probe needs to broadcast the signal so that it
remains within the system for as long as possible, outputting the optimal direction as well as the
resulting longest time. If it is possible for the signal to remain in the system indefinitely, output the
message Voyager instead of the required time.

输入格式

The first line of input contains two positive integers, N (1 ≤ N ≤ 500) and M (1 ≤ M ≤ 500).
Each of the following N lines contains M characters from the set {“/”, “\”, “C”, “.”}, where “/” and
“\” represent the two kinds of planets, “C” represents a black hole, and “.” represents an empty cell.
The last line of input contains two positive integers, PR (1 ≤ PR ≤ N) and PC (1 ≤ PC ≤ M), the row
and column number, respectively, of the cell where the probe is situated.

输出格式

The first line of output must contain the required optimal broadcast direction (“U”, “R”, “D”, or “L”).
If the solution is not unique, select the first optimal one in the following priority order: first “U”, then
“R”, then “D”, and finally “L”.
The second line of output must contain the required longest time (or message).

样例输入

5 5
../.\
.....
.C...
...C.
\.../
3 3

样例输出

U
17

题目来源

2013年每周一赛第10场/COCI 2013.1

提交

这道题很郁闷,比较简单的模拟题。因为英文水平实在是太差了。居然不能理解题意叫我在是无限时输出什么。

一直都是wa在第五组数据。。。

还是要学好英语呀!!

#include<cstdio>
#include<cstring>
char map[505][505];
int flag[505][505][5];
int d[][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int k1[] = {3,2,1,0};
int k2[] = {1,0,3,2};
int main()
{int row,col,i,j;while(scanf("%d%d",&row,&col)!=EOF){memset(map,'C',sizeof(map));for(i=1;i<=row;i++){scanf("%s",map[i]+1);map[i][col+1] = 'C';}int si,sj;scanf("%d%d",&si,&sj);int dir;int l,r,max=-1,v=0,dd;for(i=0;i<4;i++){memset(flag,0,sizeof(flag));dir = i;l = si;r = sj;flag[si][sj][i] = 1;int p = 0; int vivs = 0;while(1){if(map[l][r]=='\\'){dir = k1[dir];}if(map[l][r]=='/')dir = k2[dir];l = l+d[dir][0];r = r+d[dir][1];if(map[l][r]=='C')break;if(flag[l][r][dir]==1){vivs = 1;dd = i;break;}flag[l][r][dir] = 1;p++;}if(vivs == 1){v = 1;break;}else{v = 0;if(max<p){max = p;dd = i;}}}if(v==1){if(dd==0)printf("U\nVoyager\n");else if(dd==1)printf("R\nVoyager\n");else if(dd==2)printf("D\nVoyager\n");elseprintf("L\nVoyager\n");}else{if(dd==0)printf("U\n%d\n",max+1);else if(dd==1)printf("R\n%d\n",max+1);else if(dd==2)printf("D\n%d\n",max+1);elseprintf("L\n%d\n",max+1);}}return 0;
}

soj 9161. VOYAGER相关推荐

  1. SOJ 4543 4542

    http://acm.scu.edu.cn/soj/problem.action?id=4542 递归用数组保存中间值 #include <cstdio> #include <cma ...

  2. Soj题目分类 python代码)

    正值期末复习,刷点soj放松下 但想看看能不能在找点关于数据结构的题目来做一下. 在网上看到有不少人上传过那些关于部分SOJ题目的描述,但是说实话有些乱 不过我看到有个网页中包含的一个类似文档的东西, ...

  3. laravel 构建后台package Voyager 使用笔记

    相关信息 官网文档: https://docs.laravelvoyager.com/getting-started/what-is-voyager github: https://github.co ...

  4. Voyager,最方便的lavavel admin管理后台

    今天飞哥推荐1个最简最省心的管理后台,10分钟搭建1个功能齐全的管理后台,开箱即用,如果你在寻找方便的管理数据的管理后台,Voyager在github有11.2K star,值得推荐. 需求背景 开源 ...

  5. php lararel,Voyager 的使用及二次开发

    主要整理了我对 Laravel 的后台开源项目 Voyager 的一点经验. 一.简介 做一个 Web 系统,后台是必须的,后台大致可以分为两类: 后端导向 这里以 Laravel 为例,这类后台的特 ...

  6. Voyager的安装及配置文件

    使用代理服务器安装laravel http_proxy=http://localhost:1080 composer create-project --prefer-dist laravel/lara ...

  7. laravel voyager 笔记

    https://laravelvoyager.com/academy/custom-menus/ Voyager is a Laravel Admin Package that includes BR ...

  8. Voyager的路由

    修改默认的后台登录路由 打开web.php,把prefix值改为你想设置的值,如back: Route::group(['prefix' => 'back'], function () { Vo ...

  9. FTP voyager使用配置参考

    1.使用"360软件管家"搜索ftp voyager最新版,安装完成. 2.打开FTP voyager,提示"站点配置文件管理器"向导 3.选择"使用 ...

最新文章

  1. 广播风暴及STP生成树协议
  2. 数论概论(Joseph H.Silverman) 定理39.2 连分数相邻收敛项之差定理
  3. 利用反射实现对象调用方法
  4. 安全开发之碰撞检测与伤害计算逻辑
  5. 混合云备份服务 > 数据迁移 > 文件同步 > ECS同步到NAS教程 > 文件同步
  6. 分享一款免费好用的redis客户端
  7. 小程序实现单词查询搜索及搜索的历史记录
  8. 输入框input或内容区域textarea中关于光标移动问题
  9. FOTA升级差分包编译服务器搭建
  10. 性能测试入门,其实很简单,看看这篇,好好学习
  11. Spark jars依赖问题
  12. Excel工作日计算时,怎样去除周末和节假日
  13. 跳转到新页面并清除当前页面的history记录
  14. 基于Scrapy框架爬取豆瓣《复联4》影评,并生成词云
  15. iOS面试一般性问题
  16. nginx配置禁止访问目录或禁止访问目录下的文件
  17. 小甲鱼汉诺塔代码理解
  18. Python中的pillow(PIL)
  19. .基金从业资格考试信息
  20. Git、GitHub、Gitee、GitLab的学习

热门文章

  1. 2.递归解决年龄问题
  2. Mybatis-Plus条件构造器学习and方法
  3. 用小百合学python
  4. Oracle安装 卸载干净文档
  5. Google封锁整个co.cc子域只能临时止血难以长治久安
  6. 网站汇总|有趣or猎奇|素材|免费
  7. 政府运用大数据 决策告别“拍脑袋”
  8. 2021高级消防设施操作员模拟真题集及答案解析
  9. c语言josephus问题循环链表,循环单链表(C语言,无头节点,附约瑟夫杀人问题)...
  10. 人民币升值会给我们带来什么(个人收藏)