結果

問題 No.455 冬の大三角
ユーザー kohaku_kohaku
提出日時 2016-12-06 04:16:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 79,528 KB
実行使用メモリ 44,328 KB
最終ジャッジ日時 2024-06-29 21:11:32
合計ジャッジ時間 12,401 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String [] S = new String [H];
        int [] x = new int [3];
        int [] y = new int [3];
        int n=0;
        for(int i=0; i<H; i++){
            S[i]=sc.next();
            for(int j=0; j<W; j++){
                if(S[i].charAt(j)=='*'){
                    x[n]=j;
                    y[n]=i;
                    n++;
                }
            }
        }
        while(true){
            int dx1 = x[1]-x[0];
            int dy1 = y[1]-y[0];
            int dx2 = x[2]-x[0];
            int dy2 = y[2]-y[0];
            int a = dx1*dx2+dy1*dy2;
            int b = dx1*dx1+dy1*dy1;
            int c = dx2*dx2+dy2*dy2;
            if(a*a!=b*c){
                break;
            }
            x[2]=(int)(Math.random()*W);
            y[2]=(int)(Math.random()*H);
        }
        S[y[2]]=S[y[2]].substring(0,x[2])+"*"+S[y[2]].substring(x[2]+1);
        for(int i=0; i<H; i++){
            System.out.println(S[i]);
        }
    }
}
0