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 ...
随机推荐
- .NET研发人员面试题(一)
1.简述javascript中的“=.==.===”的区别? =赋值 ==比较是否一般相等 "3"==3 //会做类型的隐式转换,true ===比较是否严格相等 " ...
- WCF学习笔记(基于REST规则方式)
一.WCF的定义 WCF是.NET 3.0后开始引入的新技术,意为基于windows平台的通讯服务. 首先在学习WCF之前,我们也知道他其实是加强版的一个面向服务(SOA)的框架技术. 如果熟悉Web ...
- [HttpClient]SSL双向实例
package com.jerry.httpclient; import java.io.File; import java.io.FileInputStream; import java.secur ...
- linux管道的容量和内部组织方式
1.管道容量 count=65536,即64KB #include<stdio.h> #include<sys/types.h> #include<unistd.h&g ...
- C# 操作mongodb 分组
c#操作mongodb的分组的简单例子: 1.首先要下载c#对应的mongodb驱动,官方下载地址:https://github.com/mongodb/mongo-csharp-driver/rel ...
- hbase 0.96 java 示例
import java.util.ArrayList; import java.util.List; import org.apache.hadoop.conf.Configuration; impo ...
- HTML5-canvas实例:刮刮乐游戏
实现方法: (1)利用canvas画布,fillRect()描绘出一个矩形(不是透明),定位盖在某个标签如div上面(这个标签写着中奖的信息) (2)globalCompositeOperation ...
- input标签文字点击变颜色
<input type="text" class="ser_input"value="从这里搜索(^_^)" onfocus=&quo ...
- Linux查看用户和组命令
在Linux系统里,我们会经常用Linux查看用户的命令,在这里我们一些命令进行了总结,总共有7个,并做了详细的解释,以便让大家更深入的理解,接下来让我们一起来看看这些命令和具体应用. 一.Linux ...
- about backbone
http://presentation.tiddr.de/backbone-presentation/introduction/index.html#Further%20issues http://m ...