ural 1197. Lonesome Knight

 

每次knight都能在水平或竖直方向移动两格,然后到向左或右偏移一格:

直接枚举:

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 const int N=8;
 6 const int M='h'-'a'+1;
 7 
 8 int solve(int x,int y){
 9     int cnt=0;
10 
11     if(x+2<=N){
12         if(y-1>=1)
13             cnt++;
14         if(y+1<=M)
15             cnt++;
16     }
17 
18     if(x-2>=1){
19       if(y-1>=1)
20             cnt++;
21         if(y+1<=M)
22             cnt++;
23     }
24 
25     if(y-2>=1){
26         if(x+1<=N)
27             cnt++;
28         if(x-1>=1)
29             cnt++;
30     }
31      if(y+2<=M){
32         if(x+1<=N)
33             cnt++;
34         if(x-1>=1)
35             cnt++;
36     }
37     return cnt;
38 }
39 
40 int main(){
41     int t;
42     cin>>t;
43     while(t--){
44             cin.get();
45         char ch;
46         ch=getchar();
47         int n;
48         cin>>n;
49         cout<<solve(n,ch-'a'+1)<<endl;
50     }
51 }

 

转载于:https://www.cnblogs.com/IKnowYou0/p/6227333.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值