此题看似很简单,但实际上有不少细节,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的更多相关文章

  1. codeforces A. Rook, Bishop and King 解题报告

    题目链接:http://codeforces.com/problemset/problem/370/A 题目意思:根据rook(每次可以移动垂直或水平的任意步数(>=1)),bishop(每次可 ...

  2. Codeforce 370A Rook, Bishop and King 数学规律

    这个题目挺有意思的,给定 起终点,要你求车,象,王分别最少要走多少步 车横竖都能走,而且每步任意走几格,所以它是最容易处理的,如果在同行或者同列,就是1,否则就是2 象要找下规律,象任意对角线都能走, ...

  3. CF Rook, Bishop and King

    http://codeforces.com/contest/370/problem/A 题意:车是走直线的,可以走任意多个格子,象是走对角线的,也可以走任意多个格子,而国王可以走直线也可以走对角线,但 ...

  4. 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 ...

  5. codeforces 463C. Gargari and Bishops 解题报告

    题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...

  6. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)

    Problem G: Check The Check Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 3[Submit][Statu ...

  7. 使用虚幻引擎中的C++导论(四-内存管理与垃圾回收)(终)

    使用虚幻引擎中的C++导论(四)(终) 第一,这篇是我翻译的虚幻4官网的新手编程教程,原文传送门,有的翻译不太好,但大体意思差不多,请支持我O(∩_∩)O谢谢. 第二,某些细节操作,这篇文章省略了,如 ...

  8. UE4 中的 C++ 编程介绍

    https://docs.unrealengine.com/latest/CHN/Programming/Introduction/index.html UE4 中的 C++ 编程介绍 Unreal ...

  9. A Deep Dive Into Draggable and DragTarget in Flutter

    https://medium.com/flutter-community/a-deep-dive-into-draggable-and-dragtarget-in-flutter-487919f6f1 ...

随机推荐

  1. google map android api v2

    我在这主要列举几个需要注意的问题: 1.需要注意使用的api版本的问题,例如google map android api v1就和v2差别很大,包括申请key方面,所以在搜索资料的时候一定注意版本问题 ...

  2. sprintf函数php的详细使用方法

    PHP sprintf() 函数 先说下为什么要写这个函数的前言,这个是我在微信二次开发的一个token验证文档也就是示例文档看到的一个函数,当时非常不理解,于是查了百度,但是很多结果都很笼统,结果也 ...

  3. PHP学习笔记(5) - 选择一个合格的框架

    作为一个合格的PHP开发框架,个人觉得起码需要满足以下几点. 一.上梁不正下梁歪,好的框架首先自身要有良好的编码规范和文件目录结构,代码要易于阅读理解. 二.为了可以更好地适应OOP,框架必须可以提供 ...

  4. nginx错误日志error_log日志级别

    error_log 级别分为 debug, info, notice, warn, error, crit  默认为crit,

  5. Boost format

    浅尝boost之format 概述      std::string是个很不错的东东,但实际使用时基本在每个程序里都会遇到不愉快的事情:格式化字符串.我甚至由于这个原因在代码里引入平台有关的MFC,A ...

  6. Drupal commerce 性能优化

    从开始的时候打开一个页面需要超过9秒的时间到现在可以在3秒内打开,给自己带来了很多欣慰. 开始的时候是认为server性能不足,所以讲aliyun服务器从1核升级到了4核,但是发现升级之后和升级之前是 ...

  7. codeforces edu round3

    B. The Best Gift  传送门:http://codeforces.com/problemset/problem/609/B Emily's birthday is next week a ...

  8. cocos2dx android平台事件系统解析

    对于cocos2dx在android平台事件的响应过程很模糊,于是分析了下源码,cocos2dx 版本3.4,先导入一个android工程,然后看下AndroidManifest.xml <ap ...

  9. 服务器环境搭建系列(三)-JDK篇

    1.如果系统已经有jdk,卸载之. rpm -qa|grep java rpm -e --nodeps 上面命令返回的软件包名字 或者 yum -y remove 上面命令返回的包名 下载bin文件, ...

  10. 西门子plc串口通讯方式

    西门子plc串口通讯的三种方式 时间:2015-10-25 14:31:55编辑:电工栏目:西门子plc 导读:西门子plc串口通讯的三种方式,分为RS485 串口通信.PPI 通信.MPI 通信,自 ...