結果

問題 No.2632 Center of Three Points in Lp Norm
ユーザー maksimmaksim
提出日時 2024-02-16 23:01:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,625 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 169,448 KB
実行使用メモリ 16,936 KB
最終ジャッジ日時 2024-02-16 23:01:13
合計ジャッジ時間 8,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
#define double long double
#define pt pair<double,double>
#define x first
#define y second
pt operator*(double c,pt a) {return pt(c*a.x,c*a.y);}
pt operator-(pt a,pt b) {return pt(a.x-b.x,a.y-b.y);}
pt operator+(pt a,pt b) {return pt(a.x+b.x,a.y+b.y);}
double p;
double dist(pt a,pt b)
{
    return pow(abs(a.x-b.x),p)+pow(abs(a.y-b.y),p);
}
pt a[3];
double f2(pt u)
{
    return abs(dist(u,a[0])-dist(u,a[1]));
}
double f(double x)
{
    double low=(-1e7);double up=1e7;
    for(int it=0;it<100;++it)
    {
        double yl=(2*low+up)/3;double yr=(low+2*up)/3;
        if(f2(pt(x,yl))<f2(pt(x,yr))) {up=yr;} else {low=yl;}
    }
    return (low+up)/2.0;
}
double g(pt u)
{
    return abs(dist(u,a[0])-dist(u,a[2]));
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>p;for(int i=0;i<3;++i) cin>>a[i].x>>a[i].y;
    double low=(-1e7);double up=1e7;
    for(int it=0;it<10000;++it)
    {
        double xl=(9*low+up)/10;double xr=(low+9*up)/10;
        double yl=f(xl);double yr=f(xr);
        debug(xl,yl);debug(xr,yr);
        double gl=g({xl,yl});double gr=g({xr,yr});
        debug(g(pt(xl,yl)));
        if(gl<gr) {up=xr;} else {low=xl;}
    }
    double x=(low+up)/2.0;
    double y=f(x);
    cout<<fixed<<setprecision(25)<<x<<' '<<y;
    return 0;
}
0