結果
| 問題 |
No.245 貫け!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-04 02:27:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,334 bytes |
| コンパイル時間 | 869 ms |
| コンパイル使用メモリ | 85,676 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 23:40:20 |
| 合計ジャッジ時間 | 1,748 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 8 WA * 8 |
ソースコード
#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 (m.x == n.x && m.y == n.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;
}