-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvilCakeCutter.cpp
More file actions
46 lines (36 loc) · 999 Bytes
/
Copy pathEvilCakeCutter.cpp
File metadata and controls
46 lines (36 loc) · 999 Bytes
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
#include<bits/stdc++.h>
using namespace std;
class EvilCakeCutter{
public:
double successProbability(int W, int H, int W1, int H1){
double w=W,h=H,w1=W1,h1=H1;
double avA=(w-w1)*(h-h1);
double prob=0;
if(avA==0){
prob=0;
return 0;
}
if((h-2*h1)<0 && (w-2*w1)<0){
return prob;
}
if((h-2*h1)>=(h/2) || (w-2*w1)>=(w/2)){
prob=1;
return 1;
}
// double area=2*(max(h-2*h1,0))*(w-w1)+2*(max(0,w-2*w1))*(3*h1-h);
double area=0;
area+=2*(max(0.0,h-2*h1)*(w-w1));
area+=2*(max(0.0,w-2*w1)*(h-h1));
area-=4*(max(0.0,h-2*h1)*max(0.0,w-2*w1));
prob=area/avA;
return prob;
}
};
int32_t main(){
ios::sync_with_stdio(false);
EvilCakeCutter E;
cout<<E.successProbability(3,2,1,1)<<"\n";
cout<<E.successProbability(2,2,1,1)<<"\n";
cout<<E.successProbability(8,5,3,2)<<"\n";
return 0;
}