結果

問題 No.245 貫け!
ユーザー ctyl_0ctyl_0
提出日時 2015-09-04 02:31:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,342 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 80,884 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-26 04:17:39
合計ジャッジ時間 1,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 22 ms
4,376 KB
testcase_18 AC 22 ms
4,376 KB
testcase_19 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// point
class point{
public:
    double x;
    double y;
    point(double x, double y){
        this -> x = x;
        this -> y = y;
    }
};

// 直線mnが線分pqを貫くか?
bool isOnLine(point m, point n, point p, point q){
    bool ret = false;
    // 直線mnの方程式 ax + by + c = 0
    double a = n.y - m.y;
    double b = -(n.x - m.x);
    double c = n.x * m.y - m.x - n.y;
    
    // 線分pqをm:(1-m)に内分した点iを直線mnの方程式に代入 md + e = 0
    double d = a * q.x - a * p.x + b * q.y - b * p.y;
    double e = a * p.x + b * p.y + c;
    if (d == 0 && e == 0) {
        // 線分pqは直線mn上にある
        ret = true;
    }
    if (-e / d >= 0 && -e / d <= 1) {
        // 線分pqは直線mnを貫いている
        ret = true;
    }
//    if (p.x == q.x && p.y == q.y) {
//        // 1点を通る直線は不定
//        ret = false;
//    }
    if (d == 0 && b * e + c != 0) {
        // そもそも方程式が成立しないケース:平行
        ret = false;
    }
    return ret;
}

vector<point> P;

int main(int argc, const char * argv[]) {
    
    // source code
    int N = inputValue();
    rep(i, 2 * N){
        P.push_back(point(inputValue(), inputValue()));
    }
    
    int ret = 0;
    rep(i, 2 * N){
        repd(j, i + 1 , 2 * N){
            int pass = 0;
            rep(k, N){
                if (isOnLine(P[i], P[j], P[2 * k], P[2 * k + 1])) {
                    pass++;
                }
            }
            ret = max(ret, pass);
        }
    }
    
    output(ret, 0);
    
    return 0;
}
0