結果

問題 No.61 リベリオン
ユーザー goodbatongoodbaton
提出日時 2015-08-06 00:37:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,482 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 72,312 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:19:47
合計ジャッジ時間 1,049 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 15 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d%d%d%d%d%d%d%d%d",&w,&h,&d,&mx,&my,&hx,&hy,&vx,&vy);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000009
#define INF 10000000
#define LLINF 2000000000000000000LL
#define PI 3.1415926536

#define SIZE 101

int gcd(int a,int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

int main(){
    int q;
    
    scanf("%d",&q);
    
    for(int i=0;i<q;i++){
        int w,h,d,mx,my,hx,hy,vx,vy,G;
        bool visit[30][30]={0},ans=false,fx,fy;
        
        scanf("%d%d%d%d%d%d%d%d%d",&w,&h,&d,&mx,&my,&hx,&hy,&vx,&vy);
        
        if(vx<0){
            hx=w*2-hx;
            vx=abs(vx);
        }
        if(vy<0){
            hy=h*2-hy;
            vy=abs(vy);
        }
        
        G = gcd(vx,vy);
        
        vx/=G;
        vy/=G;
        d*=G;
        
        for(int i=0;i<d;i++){
            hx+=vx;
            hy+=vy;
            
            hx%=2*w;
            hy%=2*h;
            
            if(visit[hx][hy]) break;
            visit[hx][hy]=true;
            
            fx = mx==hx || hx==w*2-mx;
            fy = my==hy || hy==h*2-my;

            if(fx && fy){
                ans=true;
                break;
            }
        }
        
        if(ans)
            puts("Hit");
        else
            puts("Miss");
        
    }
    
    return 0;
}
0