結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2020-11-02 15:14:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 709 bytes |
| コンパイル時間 | 684 ms |
| コンパイル使用メモリ | 78,928 KB |
| 実行使用メモリ | 9,916 KB |
| 最終ジャッジ日時 | 2024-07-22 06:15:39 |
| 合計ジャッジ時間 | 17,885 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 24 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
using ld = long double;
int n;
vector<ld> a, b;
ld func(ld x) {
ld ret = 0;
for (int i = 0; i < n; i++) ret += b[i] * abs(x - a[i]);
return ret;
}
int main() {
cin >> n;
a.resize(n), b.resize(n);
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < n; i++)cin >> b[i];
ld mi = -1e7, ma = 1e7;
while (ma - mi > 1e-10) {
ld x = (ma + mi * 2) / 3, y = (ma * 2 + mi) / 3;
if (func(x) > func(y))mi = x;
else ma = y;
}
cout << fixed << setprecision(1) << (ma + mi) / 2 << " " << (long long) func((ma + mi) / 2) << endl;
return 0;
}
mencotton