結果

問題 No.635 自然門松列
ユーザー RyuRyu
提出日時 2018-01-20 11:25:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 650 ms
コード長 1,449 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 83,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 08:50:16
合計ジャッジ時間 1,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

bool check(double a, double b, double c)
{
    return a != b && b != c && c != a && ((a < b && c < b) || (a > b && c > b));
}

bool solve(double x1, double x2, double x3, double y1, double y2, double y3)
{
    if (check(x1, x2, x3))
        return true;
    if (check(y1, y2, y3))
        return true;

    double tl = 0.0;
    double th = 1e9;
    double tc;

    rep(i, 80)
    {
        tc = (tl + th) / 2;

        if (check(x1 + y1 * tc, x2 + y2 * tc, x3 + y3 * tc))
            return true;

        if ((x1 + y1 * (-1e9) < x3 + y3 * (-1e9)) == (x1 + y1 * tc < x3 + y3 * tc))
            tl = tc;
        else
            th = tc;
    }

    return false;
}


int main()
{
    int n;
    double x1, x2, x3, y1, y2, y3;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> x1 >> x2 >> x3 >> y1 >> y2 >> y3;

        if (solve(x1, x2, x3, y1, y2, y3))
            cout << "YES" << endl;
        else 
            cout << "NO" << endl;
    }
    return 0;
}
0