ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2010. Sasha the Young Grandmaster

#wa 20 What's wrong ?
Posted by spidey 16 Feb 2016 12:30
This is my code

import java.util.*;

public class Task_2010 {
 static void kingStep(int n, int x, int y){
  long countKing = 0;
  if((x - 1) > 0) countKing++;
  if((x - 1) > 0 && y + 1 <= n) countKing++;
  if((y + 1) <= n) countKing++;
  if((x + 1) <= n && (y + 1) <= n) countKing++;
  if((x + 1) <= n) countKing++;
  if((x + 1) <= n && (y - 1) > 0) countKing++;
  if((y - 1) > 0) countKing++;
  if((x - 1) > 0 && (y - 1) > 0) countKing++;
  System.out.println("King: " + countKing);
 }
 static void knightStep(int n, int x, int y){
  long countKnight = 0;
  if((x - 2) > 0 && (y + 1) <= n) countKnight++;
  if((x - 2) > 0 && (y - 1) > 0) countKnight++;
  if((y + 2) <= n && (x - 1) > 0) countKnight++;
  if((y + 2) <= n && (x + 1) <= n) countKnight++;
  if((x + 2) <= n && (x + 1) <= n) countKnight++;
  if((x + 2) <= n && (y - 1) > 0) countKnight++;
  if((y - 2) > 0 && (x + 1) <= n) countKnight++;
  if((y - 2) > 0 && (x - 1) > 0) countKnight++;
  System.out.println("Knight: " + countKnight);
 }
 static long bishopStep(int n, int x, int y) {
  long countBishop = 0;
  int left = x - 1;
  int right = n - x;
  if(y + left <= n){
    countBishop += left;
  } else countBishop += n - y;
  if(y + right <= n){
    countBishop += right;
  } else countBishop += n - y;
  if(y - left > 0){
    countBishop += left;
  } else countBishop += y - 1;
  if(y - right > 0){
    countBishop += right;
  } else countBishop += y - 1;
  System.out.println("Bishop: " + countBishop);
  return countBishop;
 }
 static long rookStep(int n, int x, int y){
  long countRook = (x - 1) + (n - x) + (y - 1) + (n - y);
  System.out.println("Rook: " + countRook);
  return countRook;

 }
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int x = sc.nextInt();
  int y = sc.nextInt();

  kingStep(n,x,y);
  knightStep(n,x,y);
  long queen = (bishopStep(n,x,y) + rookStep(n,x,y));
  System.out.println("Queen: " +  queen);

 }
}
Re: #wa 20 What's wrong ?
Posted by shadow_monk 27 Nov 2016 17:30
опечатка в knightStep.