結果
| 問題 |
No.635 自然門松列
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-19 22:20:54 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 650 ms |
| コード長 | 3,874 bytes |
| コンパイル時間 | 2,357 ms |
| コンパイル使用メモリ | 78,256 KB |
| 実行使用メモリ | 38,292 KB |
| 最終ジャッジ日時 | 2024-06-23 08:47:33 |
| 合計ジャッジ時間 | 4,479 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
ソースコード
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;
}
}
}
夕叢霧香(ゆうむらきりか)