CodeForces 370A Rook, Bishop and King
此题看似很简单,但实际上有不少细节,WA点不少。分情况处理即可。
#include<cmath>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool inMap(int x, int y){
return x > 0 && x < 9 && y > 0 && y < 9;
}
int main(){
int r1, c1, r2, c2, ans1, ans2, ans3;
//freopen("in.cpp", "r", stdin);
while(~scanf("%d%d%d%d", &r1, &c1, &r2, &c2)){
if(r1 == r2 && c1 == c2) printf("0 0 0\n");
else{
if(r1 == r2 || c1 == c2) ans1 = 1;
else ans1 = 2;
if(abs(r1 - r2) == abs(c1 - c2)) ans2 = 1;
else if(r1 == r2 || c1 == c2){
int tmp1 = abs(r1 - r2);
int tmp2 = abs(c1 - c2);
if((tmp1 % 2 == 0 && tmp1) || (tmp2 % 2 == 0 && tmp2)) ans2 = 2;
else ans2 = 0;
}
else{
int flag = 0, x[4], y[4];
for(int i = 1;i < 8;i ++){
x[0] = r1 + i, y[0] = c1 + i;
x[1] = r1 - i, y[1] = c1 + i;
x[2] = r1 + i, y[2] = c1 - i;
x[3] = r1 - i, y[3] = c1 - i;
for(int j = 0;j < 4;j ++){
if(inMap(x[j], y[j]) && abs(x[j] - r2) == abs(y[j] - c2)){
flag = 1;
break;
}
}
if(flag) break;
}
if(flag) ans2 = 2;
else ans2 = 0;
}
if(abs(r1 - r2) == abs(c1 - c2)) ans3 = abs(r1 - r2);
else{
int tmp1 = abs(r1 - r2) + abs(abs(c1 - c2) - abs(r1 - r2));
int tmp2 = abs(c1 - c2) + abs(abs(r1 - r2) - abs(c1 - c2));
ans3 = min(tmp1, tmp2);
}
printf("%d %d %d\n", ans1, ans2, ans3);
}
}
return 0;
}
CodeForces 370A Rook, Bishop and King的更多相关文章
- codeforces A. Rook, Bishop and King 解题报告
题目链接:http://codeforces.com/problemset/problem/370/A 题目意思:根据rook(每次可以移动垂直或水平的任意步数(>=1)),bishop(每次可 ...
- Codeforce 370A Rook, Bishop and King 数学规律
这个题目挺有意思的,给定 起终点,要你求车,象,王分别最少要走多少步 车横竖都能走,而且每步任意走几格,所以它是最容易处理的,如果在同行或者同列,就是1,否则就是2 象要找下规律,象任意对角线都能走, ...
- CF Rook, Bishop and King
http://codeforces.com/contest/370/problem/A 题意:车是走直线的,可以走任意多个格子,象是走对角线的,也可以走任意多个格子,而国王可以走直线也可以走对角线,但 ...
- Codeforces 3A-Shortest path of the king(BFS打印路径)
A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...
- codeforces 463C. Gargari and Bishops 解题报告
题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)
Problem G: Check The Check Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 10 Solved: 3[Submit][Statu ...
- 使用虚幻引擎中的C++导论(四-内存管理与垃圾回收)(终)
使用虚幻引擎中的C++导论(四)(终) 第一,这篇是我翻译的虚幻4官网的新手编程教程,原文传送门,有的翻译不太好,但大体意思差不多,请支持我O(∩_∩)O谢谢. 第二,某些细节操作,这篇文章省略了,如 ...
- UE4 中的 C++ 编程介绍
https://docs.unrealengine.com/latest/CHN/Programming/Introduction/index.html UE4 中的 C++ 编程介绍 Unreal ...
- A Deep Dive Into Draggable and DragTarget in Flutter
https://medium.com/flutter-community/a-deep-dive-into-draggable-and-dragtarget-in-flutter-487919f6f1 ...
随机推荐
- JQuery上传控件 jUploader 使用
jUploader 1.0 Demo Download: jquery.jUploader-1.01.js 9.75kb Download: jquery.jUploader-1.01.min.js ...
- Unity3D--学习太空射击游戏制作(二)
步骤三:创建主角 游戏的主角是一艘太空飞船,我们将使用一个飞船模型作为游戏的主角,并赋予他一个脚本,控制他的运动,游戏体的组件必须依赖于脚本才能运行. 01:在Project窗口找到Player.fb ...
- 用PHP实现单向链表
供参考,代码还可继续打磨 同时放在了我的github上:https://github.com/hheedat/demo/blob/master/learn_php/58_linked_list.php ...
- [数据库连接字符串] Access 连接字符串
[数据库连接字符串] Access 连接字符串 //ODBC 标准安全策略 Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb ...
- 宅男福利--利用Python简单爬图
Ver beta..代码粗陋. 使用说明以Windows为例, Python版本为2.7.6 确认你电脑已经安装了Python, Windows默认安装路径为C:\Python27.如果没有安装,先下 ...
- STL容器的本质
http://blog.sina.com.cn/s/blog_4d3a41f40100eof0.html 最近在学习unordered_map里面的散列函数和相等函数怎么写.学习过程中看到了一个好帖子 ...
- merge into 和 update 的效率对比
以前只考虑 merge into 只是在特定场合下方便才使用的,今天才发现,merge into 竟然会比 update 在更新数据时有这么大的改进.其实呢,merge into部分的update和u ...
- T[]与List<T>的使用时机
所有的数组类型都隐式地从System.Array这个抽象类派生,而System.Array又派生自System.Object.也就是说数组是引用类型.通过如下方式创建数组: int[] arrInt ...
- 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)-----初识WiX (转)
原文地址:http://blog.csdn.net/rryqsh/article/details/8274832 Visual Studio 打包安装七宗罪 开发.NET的人,肯定会使用Visual ...
- Linux PS 命令详解
Linux操作系统PS命令详细解析 要对系统中进程进行监测控制,用 ps 命令满足你. /bin/ps ps 是显示瞬间行程的状态,并不动态连续:如果想对进程运行时间监控,应该用 top 工具. ki ...