Author : Anwar Jahid Ruman Hossain
CSE, Batch - 6
BRUR.
Problem Statement : [ LightOJ ] 1043- Triangle Partitioning
Source : Light OJ
Category : Searching and Sorting
Algorithm : Bi-Section(Binary Search)
Verdict : Accepted
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- double TrianlgeRatio(double ab,double ac,double bc,double ad){
- double ae,de,s1,s2,largeTriangleArea,smallTriangleArea,trapheziumArea,ratio;
- ae=(ad*ac)/ab;
- de=(ad*bc)/ab;
-
- s1=(ab+ac+bc)/2.0;
- s2=(ad+de+ae)/2.0;
-
- largeTriangleArea=sqrt(s1*(s1-ab)*(s1-bc)*(s1-ac));
- smallTriangleArea=sqrt(s2*(s2-ad)*(s2-de)*(s2-ae));
- trapheziumArea=largeTriangleArea-smallTriangleArea;
-
- ratio=smallTriangleArea/trapheziumArea;
- return ratio;
- }
- double BiSection(double ab, double ac,double bc, double ratio){
- double low,high,mid,ad;
- low=0.0;
- high=ab;
- for(int i=0;i<100;i++){
- mid=(low+high)/2.0;
- ad=mid;
- if(TrianlgeRatio(ab,ac,bc,ad)>ratio)
- high=mid;
- else low=mid;
- }
- return ad;
- }
- int main(){
-
-
- int t;
- cin>>t;
- for(int i=1;i<=t;i++){
- double ab,ac,bc,ratio,result;
- cin>>ab>>ac>>bc>>ratio;
- result=BiSection(ab,ac,bc,ratio);
- cout<<"Case "<<i<<": "<<fixed<<setprecision(10)<<result<<endl;
- }
- return 0;
- }
No comments:
Post a Comment