spoj 1418 The Cats and the Mouse
来源:互联网 发布:网络安全产品排名 编辑:程序博客网 时间:2024/04/30 08:35
CATM - The Cats and the Mouse
In a rectangular field of size n by m squares there is a mouse and two cats. The mouse is the first to make a move, then each of the cats makes a move, then again its the mouse's turn, and so on. In each move both the mouse and the cats can move exactly one square vertically or horizontally. If the mouse is standing at the edge of the field then in its next move it can jump off the field and is saved from the cats. If in the next move one of the cats moves to the field with the mouse then there is no escape for the mouse ... =(
You are to write a program which, knowing the initial positions of mouse and the two cats, will find out if there is any way for the mouse to escape from the cats, assuming of course that each cat will do its best to catch the mouse.
Input
In the first line of input two integers n and m are given, not exceeding 100, where n is the number of rows, and m - the number of columns. The second line contains a number k [k <= 10], which defines the number of test cases for the given field. In the next k lines the initial positions of the mouse and the cats are given. The position in the field is given by two numbers: the first is the number of the row, the second is the number of the column. The first two integers are the coordinates of the mouse, the next four integers are the coordinates of the cats.
Output
You must output k lines with answers for each test case. The answer is YES, if the mouse can escape or NO otherwise.
Example
Input:5 332 2 1 1 3 32 3 1 3 5 23 2 1 2 4 3Output:NOYESYES
#include <cstdio>#include <cstdlib>#include <algorithm>using namespace std;int main() {int R, C, test, mr, mc, ar, ac, br, bc;int mtop, mleft, mbot, mright, ctop, cleft, cbot, cright;scanf("%d%d%d", &R, &C, &test);while(test--) {scanf("%d%d%d%d%d%d", &mr, &mc, &ar, &ac, &br, &bc);if(mr >= ar && mr >= br) printf("YESn");else if(mr <= ar && mr <= br) printf("YES\n");else if(mc >= ac && mc >= bc) printf("YES\n");else if(mc <= ac && mc <= bc) printf("YES\n");else {mtop = mr - 1;ctop = min(abs(1-ar)+abs(mc-ac), abs(1-br)+abs(mc-bc));mleft = C - mc;cleft = min(abs(mr-ar)+abs(C-ac), abs(mr-br)+abs(C-bc));mbot = R - mr;cbot = min(abs(R-ar)+abs(mc-ac), abs(R-br)+abs(mc-bc));mright = mc - 1;cright = min(abs(mr-ar)+abs(1-ac), abs(mr-br)+abs(1-bc));if(mtop < ctop || mbot < cbot || mleft < cleft || mright < cright) printf("YES\n");else printf("NO\n");}}return 0;}
- spoj 1418 The Cats and the Mouse
- The Mouse and the Keyboard
- lion and the mouse 小人物也起大作用
- Put the Mouse Down and Step Away from the Keyboard
- Put the Mouse Down and Step Away from the Keyboard
- SPOJ 1. Life, the Universe, and Everything
- spoj 1 Life, the Universe, and Everything
- The Mouse Love The Rice
- test the mouse events
- Chapter 7 The mouse
- Scrolling with the Mouse
- hiho1227--The Cats' Feeding Spots
- 【HIHOCODER】The Cats' Feeding Spots
- Getting Input from the Mouse
- One of the Mouse Event
- The PS/2 Mouse Interface
- adds events to the mouse
- Win32 Series - Capturing the Mouse
- Cookie 在前端中的实践
- 练习 16:处理进程,ps,kill
- github上传步骤
- gsdv
- BZOJ1090 [SCOI2003]字符串折叠
- spoj 1418 The Cats and the Mouse
- Root of AVL Tree 平衡二叉树C语言完成
- WPF Bingding总结
- 【deeplearning.ai】第二门课:提升深层神经网络——正则化的编程作业
- 如何让前端动画变得更加自然
- 安卓动画总结
- 超简单数据库解锁
- JQuery EasyUI 选项卡打开与关闭(9)
- Android 操作系统基础