結果
| 問題 | No.61 リベリオン | 
| コンテスト | |
| ユーザー |  purple_jwl | 
| 提出日時 | 2015-03-31 00:44:56 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 37 ms / 5,000 ms | 
| コード長 | 1,599 bytes | 
| コンパイル時間 | 1,264 ms | 
| コンパイル使用メモリ | 159,576 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-13 16:14:16 | 
| 合計ジャッジ時間 | 1,629 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 4 | 
コンパイルメッセージ
main.cpp: In function ‘int getDir(int, int)’:
main.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^
            
            ソースコード
#include <bits/stdc++.h>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
int getDir(int x, int y) {
  if(x >= 0 && y >= 0) return 0;
  if(x >= 0 && y < 0)  return 1;
  if(x < 0 && y >= 0)  return 2;
  if(x < 0 && y < 0)   return 3;  
}
int main() {
  // ios_base::sync_with_stdio(false);
  int Q;
  cin >> Q;
  rep(i, Q) {
    int W, H, D, mx, my, hx, hy, vx, vy;
    cin >> W >> H >> D >> mx >> my >> hx >> hy >> vx >> vy;
    int d = __gcd(abs(vx), abs(vy));
    vx /= d;
    vy /= d;
    D *= d;
    
    bool visited[H + 1][W + 1][4];
    memset(visited, false, sizeof(visited));
    visited[hy][hx][getDir(vx, vy)] = true;
    
    rep(j, D) {
      int nx = hx + vx;
      int ny = hy + vy;
      while(nx < 0 || W < nx || ny < 0 || H < ny) {
        if(nx < 0) {
          vx *= -1;
          nx = abs(nx);
        }
        if(W < nx) {
          vx *= -1;
          nx = 2 * W - nx;
        }
        if(ny < 0) {
          vy *= -1;
          ny = abs(ny);
        }
        if(H < ny) {
          vy *= -1;
          ny = 2 * H - ny;
        }
      }
      if(visited[ny][nx][getDir(vx, vy)]) break;
      visited[ny][nx][getDir(vx, vy)] = true;
      hx = nx;
      hy = ny;
    }
    bool ans = false;
    rep(j, 4) ans |= visited[my][mx][j];
    cout << (ans ? "Hit" : "Miss") << endl;
  }
  return 0;
}
            
            
            
        