手玩一下样例可以想到这样的三角形:
即高在圆心和给定的连线上,且一个顶点在在这条直线和圆的另一侧交点上(图中点 )。
令给定点到圆心的距离为 。
接下来讨论高应当取多少:
如果 ,此时随着
增加,底也在增加,所以面积一定小于
的情况。
所以只需考虑 的情况。
,是一个凸函数,三分或者求导求极值即可。
注意特判 的情况(有些写法会出现
)。
const db eps = 1e-12;
typedef pair<db, db> PDD;
void solve(){
ll r,s,x,y,x0,y0;cin>>r>>x>>y>>s>>x0>>y0;
db d = sqrt((db)1.0*((x-x0)*(x-x0)+(y-y0)*(y-y0)));
function<db(db)> area = [&](db mid){
db len = 2*sqrt(r*r-mid*mid);
db h = mid + r;
db area = len * h /2;
return area;
};
function<db()> cal = [&]{
db l = 0, r = d;
while(r-l>eps){
db mid1 = l + (r-l)/3;
db mid2 = r - (r-l)/3;
if(area(mid1)<area(mid2)){
l = mid1;
}
else{
r = mid2;
}
}
return l;
};
db mxd = cal();
db mxarea = area(mxd);
if(mxarea > s || fabs(mxarea-s)<eps){
PDD t;
if(fabs(d)<eps){
t = {1, 0};
}
else{
t = {(x0-x)/d, (y0-y)/d};
}
db len = 2*sqrt(r*r-mxd*mxd);
db x2 = x +t.fi *mxd, y2 = y + t.se*mxd;
PDD t2 = {t.se*len/2, -t.fi*len/2};
PDD p1 = {x2+t2.fi, y2+t2.se};
PDD t3 = {-t.se*len/2, t.fi*len/2};
PDD p2 = {x2+t3.fi, y2+t3.se};
PDD t4 = {-t.fi*r, -t.se*r};
PDD p3 = {x+t4.fi, y+t4.se};
cout<<p1.fi<<' '<<p1.se<<' '<<p2.fi<<' '<<p2.se<<' '<<p3.fi<<' '<<p3.se<<'\n';
}
else{
cout<<-1<<'\n';
}
}
c++火车头
// FZANOTFOUND
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ne " -> "
#define sep "======"
#define fastio ios::sync_with_stdio(false);cin.tie(0);
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
typedef pair<long long,long long> PLL;
typedef tuple<ll,ll,ll> TLLL;
const ll INF = (ll)2e18+9;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const db PI = 3.14159265358979323;
//io functions
inline void rd(ll &x){x=0;short f=1;char c=getchar();while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-') f=-1,c=getchar();while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();x*=f;}
inline ll read(){ll x=0;short f=1;char c=getchar();while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-') f=-1,c=getchar();while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();x*=f;return x;}
inline void pt(ll x){if(x<0) putchar('-'),x=-x;if(x>9) pt(x/10);putchar(x%10+'0');}
inline void print(ll x){pt(x), puts("");}
inline void print(PLL x){pt(x.fi), putchar(' '), pt(x.se), putchar('\n');}
inline void print(vector<ll> &vec){for(const auto t:vec)pt(t),putchar(' ');puts("");}
inline void print(const map<ll, ll>& g) {for(const auto& [key, value]:g){cout<<"key: "<<key<<ne<<value<<" ";}puts("");}
inline void print(vector<PLL> &vec){puts(sep);for(const auto v:vec){print(v);}puts(sep);}
inline void print(const map<ll, vector<ll>>& g) {for (const auto& [key, value] : g) { cout << "key: " << key << ne;for (const auto& v : value) {cout << v << " ";}cout << endl;}}
//fast pow
ll ksm(ll a, ll b=MOD-2, ll M=MOD){a%=M;ll res=1;while(b){if(b&1){res=(res*a)%M;}a=(a*a)%M;b>>=1;}return res;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());//rng()
ull randint(ull l, ull r){uniform_int_distribution<unsigned long long> dist(l, r);return dist(rng);}
void init(){
}
void solve(){
}
int main(){
fastio;
cout<<fixed<<setprecision(10);
init();
ll t = 1;
//t = read();
while(t--){
solve();
}
}

京公网安备 11010502036488号