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 ...
随机推荐
- linux 源码安装软件原理
make 与 configure 在使用类似 gcc 的编译器来进行编译的过程并不简单,因为一套软件并不会仅有一支程序,而是有一堆程序码文件.所以除了每个主程序与副程序均需要写上一笔编译过程的命令外, ...
- 《jQuery UI开发指南》勘误收集
此书由罗晴明 (http://weibo.com/sunnylqm)和我合译完成,此篇博客作为勘误收集而用,若译文有误或者有任何疑问,欢迎留下评论,或者给我发邮件(地址:gzooler@gmail.c ...
- js中的callback(阻塞同步或异步时使用)
1.回调就是一个函数的调用过程,函数a有一个参数,这个参数是个函数b,当函数a执行完以后执行函数b, 那么这个过程就叫回调 eg. function a(callback){ alert('paren ...
- sae-xhprof调试性能
1. 在storage中创建xhprof的domain 2.在xhprof中,给对应的版本应用开启调试 3.在版本内的代码加入 sae_xhprof_start(); // 需要调优的代码 // .. ...
- 推荐一款好用的java反编译软件——JavaDecompiler
这款反编译器叫 "Java Decompiler",在网上也是久负盛名,最近因为工作需要找来用了下,果然不错,之前都是用eclipse的插件jad来看源码的.下面这个链接是Java ...
- python--threading多线程总结
threading用于提供线程相关的操作,线程是应用程序中工作的最小单元.python当前版本的多线程库没有实现优先级.线程组,线程也不能被停止.暂停.恢复.中断. threading模块提供的类: ...
- python 中函数的参数
一.python中的函数参数形式 python中函数一般有四种表现形式: 1.def function(arg1, arg2, arg3...) 这种是python中最常见的一中函数参数定义形式,函数 ...
- 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 ...
- C语言基础知识-循环结构
用while打印出1~100之间7的倍数 int i = 1; while循环是当条件表达式的结果为真时,执行大括号里面的循环体,重复执行直到条件表达式的结果为假时结束循环. w ...
- ExtJS4中initComponent和constructor的区别
Ext的define方法参数类型define( String className, Object data, Function createdFn ) 创建自定义类时,先构造(constructor) ...