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 ...
随机推荐
- A Case for Flash Memory SSD in Enterprise Database Applications
通过分析固态硬盘的特性对数据库中不同对象,如:表,索引,回滚段,重做日志等的应用进行具体研究,最后将数据库中不同的对象进行区别应用
- mysql 之权限介绍
转自:http://tech.it168.com/a2010/0114/837/000000837456_all.shtml 一.MySQL授权表概述首先从全局开始,如果全局的是允许的,即在 user ...
- SQL Server2008数据库导入导出兼容性处理
使用场景:SQL Server 的高版本数据库恢复到低版本则可能会有兼容性问题,为了解决此类问题进行数据库脚本模式处理,数据库结构,及数据存储更换版本等. 1. 选择要导出的数据库,右键任务,生成脚 ...
- linux下python导出sybase 数据库 表记录的方式
导出sybase 数据库 表记录的方式 1 执行启动sybase 数据库命令 code : dbeng7 gkdb 2 执行 连接sybase 数据库命令code : dbisql -c " ...
- Extension method for type
扩展其实真的很简单 msdn是这样规定扩展方法的:"扩展方法被定义为静态方法,但它们是通过实例方法语法进行调用的. 它们的第一个参数指定该方法作用于哪个类型,并且该参数以 this 修饰符为 ...
- hdu 3336 Count the string KMP+DP优化
Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...
- 2014年度辛星html教程夏季版第五节
如果读者是一位后台开发者,那么肯定会知道什么叫表单,这里我们就介绍一下前台如何使用表单,表单的使用也是我们编写网页的必须经历的一关,而且,表单也往往是我们网站的漏洞和弱点出现的地方. ******** ...
- 【方言】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 几种 方言配置差异 <?xml v ...
- Xcode 7.3.1的模拟器路径
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Core ...
- UGUI-组件
2015-06-22 UGUI 组件 Canvas 画布 The Canvas component represents the abstract space in which the UI is l ...