POJ 1657
来源:互联网 发布:pkpm钢结构计算软件 编辑:程序博客网 时间:2024/05/16 12:48
题意:难得一道中文题目。。。不解释了(⊙o⊙)…
传送门:http://poj.org/problem?id=1657
思路:定义strings,g;
s代表起始位置,g代表目标位置;
王:取abs(g[0]-s[0])与abs(g[1]-s[1])中较大的;
王后:当情况满足g[0]==s[0]||g[1]==s[1]||abs(g[0]-s[0])==abs(g[1]-s[1])时,取1,否则取2;
车:当情况满足g[0]==s[0]||g[1]==s[1]时,取1,否则取2;
象(最蛋疼的):当满足abs(g[0]-s[0])==abs(g[1]-s[1])时取1,
满足g[0]==s[0]&&(abs(g[1]-s[1]==2)||abs(g[1]-s[1]==4)||abs(g[1]-s[1]==6))或
g[1]==s[1]&&(abs(g[0]-s[0]==2)||abs(g[0]-s[0]==4)||abs(g[0]-s[0]==6))时,取2,
象取2时,要求g[0]==s[0](g[1]==s[1]),并且从s[1]到g[1](s[0]到g[0])的格子数为奇数,包括s[1],g[1](s[0],g[0])在内。
其他情况取Inf。
代码:
#include<iostream>
#include<string>
#include<cmath>
usingnamespace std;
inlineint max(int &a,int &b)
{
return a>b?a:b;
}
intmain()
{
string s,g;
int n,k,q,c,e;
cin>>n;
while(n--)
{
cin>>s>>g;
if(s==g){cout<<0<<""<<0<<""<<0<<""<<0<<endl;continue;}
k=max(abs(g[0]-s[0]),abs(g[1]-s[1]));
if(g[0]==s[0]||g[1]==s[1]||abs(g[0]-s[0])==abs(g[1]-s[1]))q=1;
else q=2;
if(g[0]==s[0]||g[1]==s[1])c=1;
else c=2;
if(abs(g[0]-s[0])==abs(g[1]-s[1]))e=1;
else if(g[0]==s[0]&&(abs(g[1]-s[1]==2)||abs(g[1]-s[1]==4)||abs(g[1]-s[1]==6)))e=2;
else if(g[1]==s[1]&&(abs(g[0]-s[0]==2)||abs(g[0]-s[0]==4)||abs(g[0]-s[0]==6)))e=2;
else e=0;
if(e==0)cout<<k<<""<<q<<""<<c<<""<<"Inf"<<endl;
else cout<<k<<""<<q<<""<<c<<""<<e<<endl;
}
return 0;
}
#include<string>
#include<cmath>
using
inline
{
}
int
{
}
- POJ 1657
- poj 2488
- POJ 3299
- poj 1905
- POJ 2485 Highways
- POj 1017 Packets
- poj 1020 搜索
- poj 3278 宽搜
- poj 1426 宽搜
- poj 1925 Spiderman
- poj 3259 Wormholes
- POJ 2160 BOX
- POJ 2190 ISBN
- poj 3299 humidex
- poj 2253 Frogger
- poj 2485 Highways
- poj 3041 Asteroids
- poj 数论 1845
- 点名,你随意
- POJ 1504
- POJ 1552
- C++学习书籍推荐
- POJ 1607
- POJ 1657
- POJ 1674
- POJ 1799
- POJ 1862
- POJ 1906
- POJ 1922
- POJ 1929
- POJ 1969
- POJ 2000