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 }
时间: 2024-10-03 14:51:56

ural 1197. Lonesome Knight的相关文章

【计算几何】URAL - 2101 - Knight&#39;s Shield

Little Peter Ivanov likes to play knights. Or musketeers. Or samurai. It depends on his mood. For parents, it is still always looks like "he again found a stick and peels the trees." They cannot understand that it is a sword. Or epee. Or katana.

URAL 1298 knight dfs搜索

1298. Knight Time limit: 2.0 second Memory limit: 64 MB Even paratroopers have vacations. The flight to Sirius in the depths of "The Admiral Brisco" Leo Hao whiled away with chessboard. No, he did not like usual chess game, and in addition, he d

URAL 1298. Knight(DFS啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1298 1298. Knight Time limit: 2.0 second Memory limit: 64 MB Even paratroopers have vacations. The flight to Sirius in the depths of "The Admiral Brisco" Leo Hao whiled away with chessboard.

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

POJ 1915 Knight Moves

Knight Moves Description Background Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him? The Problem Your task is to write a program to calculate the mini

POJ 1915 Knight Moves [BFS]

Knight Moves Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 26844   Accepted: 12663 Description Background  Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fas

UVa439 Knight Moves (BFS求最短路)

链接:http://acm.hust.edu.cn/vjudge/problem/19436分析:BFS跑一次最短路,状态转移有8个. 1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 using namespace std; 5 6 struct Point { 7 char r, c; 8 Point(char r = ' ', char c = ' '): r(r), c(c) {}; 9

Sicily Knight Moves(BFS)

1000. Knight Moves                       Time Limit: 1sec    Memory Limit:32MB Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square