Tuesday, 1 March 2016

/Benny and Triangle

Benny and Triangle
One day Benny decides to miss lessons. But as she is a very good pig she will do her homework anyway. She doesn't know anything about the content of this lessons. Your task is to help her.
The problem is following: you are given a right triangle with coordinates of vertices (0, 0), (0, a), (b, 0) and integer p. You may choose any value val and draw a vertical line x = val. After that let area(val) be the area of the part of triangle at the right side of this line. Your task is to find such minimal val that area(val) is not more than p% of the area of the given triangle.
Input
The first and the only one line contains three integers ab and p.
Output
Output in a single line answer to the problem with two signs after decimal point.
It is guaranteed that the answer+10-6 and answer-10-6 would produce the same rounded answer.
Constraints
  • 1 ≤ a, b ≤ 107
  • 1 ≤ p < 100
  • 1 ≤ a, b ≤ 103 holds for test cases worth 20% of the problem's score.

Sample Input
(Plaintext Link)
2 2 25
Sample Output
(Plaintext Link)
1.00




  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int lli;
  4. //typedef long int li;
  5. typedef unsigned long long int ulli;
  6. #define ini(a, v) memset(a, v, sizeof(a))
  7. #define all(x) (x).begin(), (x).end()
  8. #define ff first
  9. #define ss second
  10. #define pb push_back
  11. #define mp make_pair
  12. #define mod 1000000007
  13. #define test() int t; cin>>t;while(t--)
  14.  
  15. #define si(x) scanf("%d",&x)
  16. #define slli(x) scanf("%lld",&x)
  17. #define sli(x) scanf("%ld",&x)
  18. #define sd(x) scanf("%d",&x)
  19.  
  20. #define pfi(x) printf("%d\n",x)
  21. #define pfli(x) printf("%ld\n",x)
  22. #define pflli(x) printf("%lld\n",x)
  23.  
  24. #define abs(x) ((x)>0?(x):-(x))
  25.  
  26.  
  27. #define TRI(a,b,c) mp(mp(a,b),c)
  28.  
  29. #define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
  30. #define LB(a,x) (lower_bound(all(a),x)-a.begin()) // first element in the range [first,last) which does not compare less than val.
  31. #define UB(a,x) (upper_bound(all(a),x)-a.begin()) // first element in the range [first,last) which compares greater than val.
  32. #define all(x) x.begin(),x.end()
  33. #define sz size()
  34.  
  35. #define rep(i,a,b) for(int i=(a);i<(b);i++)
  36. #define repl(i,a,b) for(lli i=(a);i<(b);i++)
  37. #define rrep(i,a,b) for(int i=(b);i>=(a);i--)
  38. #define foreach( gg,itit ) for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
  39.  
  40. typedef pair<lli,lli> PII;
  41. typedef vector<int> VI;
  42. typedef vector<PII> VPII;
  43. vector<pair<lli,lli> > v;
  44. vector<pair<pair<lli,lli>,char > > op;
  45. int main()
  46. {
  47. double a,b,p;
  48. cin>>a>>b>>p;
  49. p=p*.01;
  50. double l=0;
  51. double r=b;
  52. double ach=(p*(b*a))/2.0;
  53. double ans=0.0;
  54. while(r-l>=0.0000001)
  55. {
  56. double mid=(l+r)/2.0;
  57. // printf("%.5lf\n",mid);
  58. double pp=(-(a*mid)+a*b)/b;
  59. double ar=(pp*(b-mid))/2.0;
  60. if(ach-ar>=0.0000001)
  61. {
  62. r=mid;
  63. ans=mid;
  64. }
  65. else
  66. {
  67. l=mid;
  68. }
  69. }
  70. printf("%.2lf",ans);
  71. return 0;
  72. }

No comments:

Post a Comment