Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <vector>
  5. #include <stack>
  6. #include <algorithm>
  7.  
  8. #include <iomanip>
  9. using namespace std;
  10. long long n;
  11. long double w,h;
  12. pair<long double,long double> a[111111];
  13.  
  14. bool check(long double k){
  15. long double tekh=k*a[0].second;
  16. long double tekw=w;
  17. long double osth=h;
  18. for (int i=0; i<n; i++){
  19. long double tekx=k*a[i].first;
  20. long double teky=k*a[i].second;
  21. if (tekw-tekx>=0 && teky==tekh && i!=0) {
  22. tekw-=tekx;
  23. }
  24. else {
  25. if (osth-teky<0) return false;
  26. if (w-tekx<0) return false;
  27. osth-=teky,tekh=teky,tekw=w-tekx;
  28. }
  29. }
  30. return true;
  31. }
  32.  
  33.  
  34. int main(){
  35.  
  36. cin>>n>>w>>h;
  37. for (int i=0; i<n; i++)
  38. cin>>a[i].first>>a[i].second;
  39. long double l=0;
  40. long double r=111111111;
  41. long double mid=(l+r)/2;
  42. for (int i=0; i<55; i++){
  43. if (check(mid)==false) {
  44. r=mid;
  45. }
  46. else {
  47. l=mid;
  48. }
  49. mid=(l+r)/2;
  50. }
  51. setprecision(10);
  52.  
  53. cout<<fixed<<mid<<endl;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement