P3382 三分 · znzryb
## 思路讲解
三分模版
注意L=mid,R=mid。
## AC代码
::: 源代码
```cpp
// Problem: P3382 三分
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3382
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int) a.size())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef long double DB;
typedef pair<DB,DB> pdd;
typedef pair<ll,bool> plb;
constexpr ll MAXN=static_cast<ll>(1e6)+10,INF=static_cast<ll>(5e18)+3;
constexpr ll mod=static_cast<ll>(1e9)+7;
constexpr DB eps=1e-8;
ll N,K,T;
DB fac[18];
DB L,R;
inline DB binpow(DB x,ll k){
DB res=1;
while(k){
if(k&1) res*=x;
k>>=1;
x*=x;
}
return res;
}
inline DB F(DB x){
DB res=0;
FOR(i,0,N){
res+=fac[i]*binpow(x,i);
}
return res;
}
inline void solve(){
cin>>N>>L>>R;
ROF(i,N,0){
cin>>fac[i];
}
while(R-L>eps){ // 保证为凸性函数在[l,r]内
DB mid=L+(R-L)/2;
if(F(mid-eps)>F(mid+eps)){
R=mid;
}else{
L=mid;
}
}
cout<<setprecision(15)<<L<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// cin>>T;
// while(T--){
// solve();
// }
solve();
return 0;
}
/*
AC
https://www.luogu.com.cn/record/215785806
*/
```
:::
## 心路历程(WA,TLE,MLE……)