Ural 1197 lonesome knight

Source: Internet
Author: User

Common determination legitimacy in BFS ......

 1 import java.util.Scanner; 2  3 public class P1197 4 { 5     private static int dx[] = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 }; 6     private static int dy[] = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 }; 7  8     private static boolean check(int x, int y) 9     {10         return (x >= 1 && x <= 8 && y >= 1 && y <= 8);11     }12 13     public static void main(String args[])14     {15         try (Scanner cin = new Scanner(System.in))16         {17             while (cin.hasNext())18             {19                 int n = cin.nextInt();20                 for (int i = 0; i < n; i++)21                 {22                     String location = cin.next();23                     int x = location.charAt(0) - ‘a‘ + 1;24                     int y = location.charAt(1) - ‘1‘ + 1;25                     int result = 0;26                     for (int dir = 0; dir < 8; dir++)27                         if (check(x + dx[dir], y + dy[dir]))28                             result++;29                     System.out.println(result);30                 }31             }32         }33     }34 }

 

Ural 1197 lonesome knight

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.