http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718

题意:如果没有障碍就按原方向直走,否则就右转直走,若右边走不通就左转直走,若左边也走不通就后转直走,直到走出去。

 #include <stdio.h>
#include <string.h>
const int N=;
using namespace std;
int a[N][N];
int main()
{
int n,m,k,x,y,p=;
while(~scanf("%d %d %d",&n,&m,&k))
{
p++;
if (n==&&m==&&k==)
break;
memset(a,,sizeof(a));
for (int j = ; j <= m+; j++)
{
a[][j] = ;
a[n+][j] = ; }
for (int i = ; i <= n+; i++)
{
a[i][] = ;
a[i][m+] = ;
}
for (int i = ; i < k; i ++)
{
scanf("%d %d",&x,&y);
a[x][y] = -;
}
int dir;
scanf("%d %d",&x,&y);
if (x==)
dir = ;
else if (x==n)
dir = ;
else if (y==m)
dir = ;
else if (y==)
dir = ;
int cnt = ;
while(a[x][y]!= )
{
cnt++;
if (dir==)
{
if (a[x+][y]!=-)
{
x++;
dir = ;
}
else
{
if (a[x][y-]!=-)
{
y--;
dir = ;
}
else
{
if (a[x][y+]!=-)
{
y++;
dir = ;
}
else
{ x--;
dir = ;
}
}
}
}
else if (dir==)
{
if (a[x][y-]!=-)
{
y--;
dir = ;
}
else
{
if (a[x-][y]!=-)
{
x--;
dir = ;
}
else
{
if (a[x+][y]!=-)
{
x++;
dir = ;
}
else
{
y++;
dir = ;
}
}
} }
else if (dir==)
{
if (a[x-][y]!=-)
{
x--;
dir = ;
}
else
{
if (a[x][y+]!=-)
{
y++;
dir = ;
}
else
{
if (a[x][y-]!=-)
{
y--;
dir = ;
}
else
{
x++;
dir = ;
}
}
}
}
else
{
if (a[x][y+]!=-)
{
y++;
dir = ;
}
else
{
if (a[x+][y]!=-)
{
x++;
dir = ;
}
else
{
if (a[x-][y]!=-)
{
x--;
dir = ;
}
else
{
y--;
dir = ;
}
}
}
}
}
if (dir==)
x--;
else if (dir==)
y++;
else if (dir==)
x++;
else
y--;
printf("Case %d: %d %d %d\n",p,x,y,cnt);
}
return ;
}

Rocky(模拟)的更多相关文章

  1. 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718 题意:优先直走,右 左 后.... ...

  2. 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】

    2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...

  3. HUNNU11342:Chemistry(模拟)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11342 Problem description The ch ...

  4. Rocky之Mysql-MHA高可用

    9.半同步复制 安装插件三种方法: 第一种: mysql>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so' 安装 在 ...

  5. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  6. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  7. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  8. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  9. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

随机推荐

  1. java实例1

    1.满天星星 import java.awt.*; public class xinxin { public static void main(String[] args) { Frame w = n ...

  2. 《C++ Primer 第5版》第1章

    1.1 一个简单的C++程序 #include <iostream>int main() {    std::cout << "Hello World!" ...

  3. MFC TAB控件顺序

    在MFC中添加控件后,按Ctrl+d可以改变控件TAB顺序,怕自己忘了,一个神奇的东西,记下. 关于改变Tab顺序的方法有以下几种: 方法一:在动态创建控件的时候STYLE设置成为WS_CHILD|W ...

  4. pip操作以及window和虚拟机中为pip更换一个国内的镜像源的方法

    前言 在学习PyQt5的过程中,参考王硕和孙洋洋的PyQt5快速开发与实战中,看到的关于Python开发技巧与实战,觉得挺好的 所以将其摘抄了下来方便阅读.之后还有一个关于更换pip镜像源的方法,方便 ...

  5. 【Codeforces 1114C】Trailing Loves (or L'oeufs?)

    [链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...

  6. 【Codeforces 158A】Next Round

    [链接] 我是链接,点我呀:) [题意] 让你找到排名的前k名,并列的话,如果分数大于0那么就算晋级 问你最后有多少人可以晋级. [题解] 按照题意模拟就好, 先按照a[max] = a[k]的规则找 ...

  7. 【[Offer收割]编程练习赛12 A】歌德巴赫猜想

    [题目链接]:http://hihocoder.com/problemset/problem/1493 [题意] [题解] 枚举P从2..n/2 如果P是质数且N-P也是质数; 则输出P和N-P就好; ...

  8. (39.4) Spring Boot Shiro权限管理【从零开始学Spring Boot】

    在读此文章之前您还可能需要先了解: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...

  9. hdu_1061_Rightmost Digit_201311071851

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. Q - Period II

    For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the ...