結果
| 問題 |
No.61 リベリオン
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-11-15 23:53:17 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 200 ms / 5,000 ms |
| コード長 | 2,048 bytes |
| コンパイル時間 | 2,139 ms |
| コンパイル使用メモリ | 114,404 KB |
| 実行使用メモリ | 31,376 KB |
| 最終ジャッジ日時 | 2024-10-13 16:13:58 |
| 合計ジャッジ時間 | 2,030 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 |
コンパイルメッセージ
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;
class Program
{
public static void Main(string[] args)
{
var q = int.Parse(Console.ReadLine());
List<string> results = new List<string>();
for (int i = 0; i < q; i++)
{
results.Add(Solve());
}
foreach (var element in results)
{
Console.WriteLine(element);
}
}
private static int Gcd(int a, int b)
{
if (b == 0)
{
return a;
}
return Gcd(b, a % b);
}
private static string Solve()
{
var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var w = line[0];
var h = line[1];
var d = line[2];
var mx = line[3];
var my = line[4];
var hx = line[5];
var hy = line[6];
var vx = line[7];
var vy = line[8];
var hit = new bool[w+1,h+1];
var g = CalculateGcd(vx, vy);
vx /= g;
vy /= g;
d *= g;
for (int i = 0; i < Math.Min(d + 1, 1025); i++)
{
var dx = hx + vx*i;
var dy = hy + vy*i;
dx %= (2 * w);
dy %= (2 * h);
dx = Math.Abs(dx);
dy = Math.Abs(dy);
if (dx >= w)
{
dx = 2 * w - dx;
}
if (dy >= h)
{
dy= 2 * h - dy;
}
hit[dx, dy] = true;
}
if (hit[mx, my])
{
return "Hit";
}
return "Miss";
}
private static int CalculateGcd(int vx, int vy)
{
int g = 0;
if (vx == 0)
{
g = Math.Abs(vy);
}
else if (vy == 0)
{
g = Math.Abs(vx);
}
else
{
g = Gcd(Math.Abs(vx), Math.Abs(vy));
}
return g;
}
}
nanophoto12