結果

問題 No.635 自然門松列
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-19 22:19:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,874 bytes
コンパイル時間 4,346 ms
コンパイル使用メモリ 73,860 KB
実行使用メモリ 52,376 KB
最終ジャッジ日時 2023-08-26 00:20:17
合計ジャッジ時間 5,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,244 KB
testcase_01 AC 45 ms
49,100 KB
testcase_02 AC 48 ms
49,172 KB
testcase_03 AC 46 ms
49,116 KB
testcase_04 AC 46 ms
49,116 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 48 ms
47,564 KB
testcase_09 AC 47 ms
49,028 KB
testcase_10 AC 59 ms
50,184 KB
testcase_11 AC 61 ms
50,424 KB
testcase_12 AC 61 ms
50,220 KB
testcase_13 AC 60 ms
50,300 KB
testcase_14 AC 61 ms
50,380 KB
testcase_15 AC 46 ms
49,172 KB
testcase_16 AC 45 ms
49,208 KB
testcase_17 AC 61 ms
50,428 KB
testcase_18 AC 60 ms
50,312 KB
testcase_19 AC 61 ms
50,200 KB
testcase_20 AC 62 ms
50,996 KB
testcase_21 AC 60 ms
50,156 KB
testcase_22 WA -
testcase_23 AC 61 ms
50,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static boolean valid(double x,double y){
        return x>1.0e-9||y<1.0e9;
    }
    static boolean solve(double[]x,double[]y){
        double eq13;
        if(y[2]==y[0]){
            if(x[0]==x[2])return false;
            eq13=-1;
        }else{
            eq13=(x[0]-x[2])/(y[2]-y[0]);
        }
        double mi1=0,ma1=1.0/0.0; // a1<=a2<=a3
        double mi2=0,ma2=1.0/0.0;
        if(y[0]<y[1]){
            double r=(x[0]-x[1])/(y[1]-y[0]);
            mi1=Math.max(mi1,r);
            ma2=Math.min(ma2,r);
        }else if(y[0]>y[1]){
            double r=(x[0]-x[1])/(y[1]-y[0]);
            ma1=Math.min(ma1,r);
            mi2=Math.max(mi2,r);
        }else{
            if(x[0]<x[1]){
                ma2=Math.min(ma2,-1);
            }else if(x[0]>x[1]){
                ma1=Math.min(ma1,-1);
            }else{
                return false;
            }
        }
        if(y[1]<y[2]){
            double r=(x[1]-x[2])/(y[2]-y[1]);
            mi1=Math.max(mi1,r);
            ma2=Math.min(ma2,r);
        }else if(y[1]>y[2]){
            double r=(x[1]-x[2])/(y[2]-y[1]);
            ma1=Math.min(ma1,r);
            mi2=Math.max(mi2,r);
        }else{
            if(x[1]<x[2]){
                ma2=Math.min(ma2,-1);
            }else if(x[1]>x[2]){
                ma1=Math.min(ma1,-1);
            }else{
                return false;
            }
        }
        if(false){
            System.err.println("int1=["+mi1+","+ma1+"]");
            System.err.println("int2=["+mi2+","+ma2+"]");
        }
        if(mi1>ma1){
            return valid(mi2,ma2);
        }
        if(mi2>ma2){
            return valid(mi1,ma1);
        }
        if(valid(Math.min(mi1,mi2),Math.max(ma1,ma2)))
            return true;
        if(mi1>1.0e-9){
            double tmp=mi2;
            mi2=mi1;
            mi1=tmp;
            tmp=ma2;
            ma2=ma1;
            ma1=tmp;
        }
        return ma1<mi2+1.0e-9;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        while(n-->0){
            double[]x=new double[3];
            double[]y=new double[3];
            for(int i=0;i<3;++i)x[i]=sc.nextInt();
            for(int i=0;i<3;++i)y[i]=sc.nextInt();
            boolean ans=solve(x,y);
            out.println(ans?"YES":"NO");
        }
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
0