标签:return str cst src cout 分享 const char turn
每次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 }
标签:return str cst src cout 分享 const char turn
原文地址:http://www.cnblogs.com/IKnowYou0/p/6227333.html