-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrisection.cpp
72 lines (67 loc) · 1.84 KB
/
Trisection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
#define re register
#define il inline
#define pb push_back
#define POS(i,l,r) for(re int i(l);i<=r;i=-~i)
#define REV(i,r,l) for(re int i(r);i>=l;i--)
#define ls(k) k<<1
#define rs(k) k<<1|1
#define np pair<int,int>
#define mp make_pair
#define nb(k) bitset<k>
#define rev reverse
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
il int read(){
int ans=0,flag=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flag=-1;ch=getchar();}
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans*flag;
}
il string reads(){
string ans="";char ch=getchar();
while(!isalpha(ch))ch=getchar();
while(isalpha(ch))ans+=ch,ch=getchar();
return ans;
}
il char readc(){
char ch=getchar();
while(!isalpha(ch))ch=getchar();
return ch;
}
il int sqr(int x){return x*x;}
void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
return;
}
const int N=21;
const double eps=1e-7;
double n,l,r,a[N],ans;
double power(double x,double y){double res=1;for(int i=1;i<=y;i++)res*=x;return res;}
double get_val(double x){double res=0;for(int i=0;i<=n;i++)res+=a[i]*power(x,n-i);return res;}
bool check(double x){if(get_val(x-eps)<get_val(x+eps))return 1;return 0;}
int main(){
cin>>n>>l>>r;
for(int i=0;i<=n;i++)cin>>a[i];
while(l<=r){
double mid=(l+r)/2;
if(check(mid))ans=mid,l=mid+eps;
else r=mid-eps;
}printf("%.6lf",ans);
return 0;
}
//LOJ loyal users:EXODUS
/*
0. Enough array size? Enough array size? Enough array size? Interger overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?
*/