結果
問題 |
No.3074 Divide Points Fairly
|
ユーザー |
|
提出日時 | 2025-03-28 22:05:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,528 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 203,344 KB |
実行使用メモリ | 7,328 KB |
最終ジャッジ日時 | 2025-03-28 22:06:04 |
合計ジャッジ時間 | 6,575 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 34 WA * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int total = 2 * N; vector<pair<int,int>> pts(total); for (int i = 0; i < total; i++){ cin >> pts[i].first >> pts[i].second; } vector<double> posThreshold, negThreshold; int countZero = 0; for (int i = 0; i < total; i++){ int x = pts[i].first, y = pts[i].second; if(x > 0){ posThreshold.push_back((y - 0.5) / x); } else if(x < 0){ negThreshold.push_back((y - 0.5) / x); } else { if(y > 0.5) countZero++; } } sort(posThreshold.begin(), posThreshold.end()); sort(negThreshold.begin(), negThreshold.end()); // f(k) = (x>0: #T > k) + (x<0: #T < k) + countZero for (int k = -50000; k <= 50000; k++){ int countPos = posThreshold.size() - (upper_bound(posThreshold.begin(), posThreshold.end(), (double)k) - posThreshold.begin()); int countNeg = lower_bound(negThreshold.begin(), negThreshold.end(), (double)k) - negThreshold.begin(); int f = countPos + countNeg + countZero; if(f == N){ int A = 2 * k; int B = -2; long long C = 1; cout << A << " " << B << " " << C; return 0; } } // 如果上述模板无解,则尝试使用经过 (0.5, 0) 模板 vector<double> posThreshold2, negThreshold2; int countVertical = 0; for (int i = 0; i < total; i++){ double d = pts[i].first - 0.5; double yy = pts[i].second; if(d > 1e-12){ posThreshold2.push_back(yy / d); } else if(d < -1e-12){ negThreshold2.push_back(yy / d); } else { if(yy > 0) countVertical++; } } sort(posThreshold2.begin(), posThreshold2.end()); sort(negThreshold2.begin(), negThreshold2.end()); for (int k = -50000; k <= 50000; k++){ int countPos2 = posThreshold2.size() - (upper_bound(posThreshold2.begin(), posThreshold2.end(), (double)k) - posThreshold2.begin()); int countNeg2 = lower_bound(negThreshold2.begin(), negThreshold2.end(), (double)k) - negThreshold2.begin(); int f2 = countPos2 + countNeg2 + countVertical; if(f2 == N){ int A = 2 * k; int B = -2; long long C = -k; cout << A << " " << B << " " << C; return 0; } } return 0; }