結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
nuwasogi
|
| 提出日時 | 2015-11-29 00:33:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| コード長 | 3,895 bytes |
| コンパイル時間 | 2,693 ms |
| コンパイル使用メモリ | 112,152 KB |
| 実行使用メモリ | 27,544 KB |
| 最終ジャッジ日時 | 2024-10-07 21:16:24 |
| 合計ジャッジ時間 | 4,692 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
namespace KnightSanpo_CS
{
class Program
{
static void Main(string[] args)
{
Solution mysol = new Solution();
if (mysol.Solve()) Console.WriteLine("YES");
else Console.WriteLine("NO");
}
}
class Solution
{
static Vector[] Moves = { new Vector(1, 2), new Vector(2, 1), new Vector(2, -1), new Vector(1, -2), new Vector(-1, -2), new Vector(-2, -1), new Vector(-2, 1), new Vector(-1, 2) };
Vector Destination;
static int SDThreshold = 45;
public bool Solve()
{
if (Destination.SquareDistance > SDThreshold || Math.Abs(Destination.X) > 8 || Math.Abs(Destination.Y) > 8)
{
return false;
}
else if (Destination.SquareDistance <= 1 || Destination.SquareDistance == 5 || Destination.SquareDistance == 20 || Destination.SquareDistance == SDThreshold)
{
return true;
}
else
{
Queue<Vector> q = new Queue<Vector>();
q.Enqueue(new Vector(0, 0));
while (q.Count() != 0)
{
Vector loc = q.Dequeue();
foreach (Vector m in Moves)
{
Vector moved = loc + m;
moved.n = loc.n + 1;
if (moved == Destination)
{
return true;
}
else
{
if (!q.Contains(moved) && moved.n <=2)
{
q.Enqueue(moved);
}
}
}
}
return false;
}
}
public Solution()
{
int[] xy = ria();
Destination = new Vector(xy[0], xy[1]);
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa() { return Console.ReadLine().Split(' '); }
static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
}
struct Vector
{
public int X, Y;
public int n;
public Vector(int x, int y)
{
X = x;
Y = y;
n = 0;
}
public Vector(Vector a)
{
X = a.X;
Y = a.Y;
n = a.n;
}
public static Vector operator +(Vector a, Vector b)
{
Vector c = new Vector(a.X + b.X, a.Y + b.Y);
return c;
}
public static Vector operator -(Vector a, Vector b)
{
Vector c = new Vector(a.X - b.X, a.Y - b.Y);
return c;
}
public static Vector operator -(Vector a)
{
Vector c = new Vector(-a.X, -a.Y);
return c;
}
public static bool operator ==(Vector a, Vector b)
{
return (a.X == b.X && a.Y == b.Y);
}
public static bool operator !=(Vector a, Vector b)
{
return (a.X != b.X || a.Y != b.Y);
}
public int SquareDistance
{
get
{
return (X * X + Y * Y);
}
}
}
}
nuwasogi