結果

問題 No.245 貫け!
ユーザー machymachy
提出日時 2015-07-18 09:08:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 2,032 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 89,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 18:55:29
合計ジャッジ時間 2,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <sys/time.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <random>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>

using namespace std;

struct Point{
    int x;
    int y;
    Point(){}
    Point(int x_, int y_):x(x_),y(y_){}
    int dist2(int x_, int y_) const{
        return (x_-x)*(x_-x) + (y_-y)*(y_-y);
    }
    int dist2(const Point& p) const{
        return dist2(p.x, p.y);
    }
    string str() const{
        stringstream st;
        st << " (" << x << "," << y << ")";
        return st.str();
    }
};

int side(const Point& a1, const Point& a2, const Point& p){
    return (a2.x - a1.x) * (p.y - a1.y) - (a2.y - a1.y) * (p.x - a1.x);
}

bool cross(const Point& a1, const Point& a2, const Point& b1, const Point& b2){
    //int s1 = side(a1, a2, b1) * side(a1, a2, b2);
    int s2 = side(b1, b2, a1) * side(b1, b2, a2);

/*
    if(s1 == 0){// && s2 == 0){ // on a line
        if(max(a1.dist2(b1), a1.dist2(b2)) < b1.dist2(b2)) return true;
        if(max(a2.dist2(b1), a2.dist2(b2)) < b1.dist2(b2)) return true;
        return false;
    }
    */

    if(s2 <= 0){// && s1 <= 0){
        return true;
    }
    return false;
}


int main(){
    int N;
    cin >> N;
    vector<pair<Point,Point> > line(N);
    vector<Point> cand(N*2);
    for(int i = 0; i < N; i++){
        cin >> line[i].first.x;
        cin >> line[i].first.y;
        cin >> line[i].second.x;
        cin >> line[i].second.y;
        cand[i*2] = line[i].first;
        cand[i*2+1] = line[i].second;
    }
    int ans = 0;
    for(int i = 0; i < cand.size(); i++){
        for(int j = 0; j < cand.size(); j++){
            if(cand[i].x == cand[j].x && cand[i].y == cand[j].y) continue;
            int cnt = 0;
            for(int k = 0; k < N; k++){
                if(cross(line[k].first, line[k].second, cand[i], cand[j])) cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;

}
0