結果

問題 No.635 自然門松列
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-19 22:20:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 63 ms / 650 ms
コード長 3,874 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 75,136 KB
実行使用メモリ 51,952 KB
最終ジャッジ日時 2023-09-05 13:08:16
合計ジャッジ時間 4,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,356 KB
testcase_01 AC 45 ms
49,556 KB
testcase_02 AC 46 ms
49,432 KB
testcase_03 AC 46 ms
49,520 KB
testcase_04 AC 45 ms
49,572 KB
testcase_05 AC 58 ms
51,952 KB
testcase_06 AC 59 ms
51,364 KB
testcase_07 AC 63 ms
50,724 KB
testcase_08 AC 47 ms
49,912 KB
testcase_09 AC 46 ms
49,684 KB
testcase_10 AC 59 ms
50,612 KB
testcase_11 AC 60 ms
50,332 KB
testcase_12 AC 59 ms
51,432 KB
testcase_13 AC 60 ms
51,528 KB
testcase_14 AC 60 ms
50,804 KB
testcase_15 AC 45 ms
49,612 KB
testcase_16 AC 44 ms
49,536 KB
testcase_17 AC 60 ms
51,692 KB
testcase_18 AC 59 ms
51,636 KB
testcase_19 AC 60 ms
50,948 KB
testcase_20 AC 61 ms
51,416 KB
testcase_21 AC 60 ms
50,792 KB
testcase_22 AC 63 ms
50,544 KB
testcase_23 AC 60 ms
50,732 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