Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, inp[50];
  6. double mans;
  7. struct point{
  8. double x, y;
  9.  
  10. point(double _x, double _y){
  11. x = _x;
  12. y = _y;
  13. }
  14. };
  15.  
  16. struct st{
  17. int x, r;
  18.  
  19. st( int _x, int _r){
  20. x = _x;
  21. r = _r;
  22. }
  23. };
  24.  
  25.  
  26. double dist(point p1, point p2){
  27. return hypot(p1.x - p2.x, p1.y - p2.y);
  28. }
  29.  
  30. double fnc2(vector<point> pt, double &an, double rd){
  31. double l = 0.0, r = an + r + 10, mid ;
  32. int fl = 0;
  33. for(int i=0; i<100; i++){
  34. mid = (l + r)/2;
  35. fl = 0;
  36. for(int j = 0; j<pt.size(); j++){
  37. if(mid<pt[j].x){
  38. l = mid; fl = 1;
  39. break;
  40. }
  41. if(dist(pt[j], point(mid, r)) < pt[j].y + rd){
  42. l = mid;
  43. fl = 1;
  44. break;
  45. }
  46. }
  47. if (fl == 0){
  48. r = mid;
  49. }
  50. }
  51. if(mid + rd > an) an = rd;
  52. return mid;
  53. }
  54.  
  55. void fnc(int i, vector<st> &rd, vector<point> &pt, double ans){
  56. cout<< i << " " << ans<<endl;
  57. if(i==n){
  58. cout << i << endl;
  59. for(int x = 0 ; x< pt.size(); x++) {
  60.  
  61. cout<< " - > " << pt[x].x << " " << pt[x].y<<endl;
  62. }
  63. if (ans < mans )mans = ans;
  64. return;
  65. }
  66. double tmp;
  67. for(int j=0; j<rd.size(); j++){
  68. if(rd[j].r > inp[i]){
  69. tmp = rd[j].r ;
  70. rd[j].r = inp[i];
  71. pt.push_back(point(rd[j].x, inp[i]));
  72. fnc(i+1, rd, pt, ans);
  73. rd[j].r = tmp;
  74. pt.pop_back();
  75. }
  76. }
  77. double tm = ans;
  78. double x = fnc2(pt, tm, inp[i]);
  79. pt.push_back(point(x, inp[i]));
  80. fnc(i+1, rd, pt, tm);
  81. pt.pop_back();
  82. }
  83.  
  84. int main(){
  85. freopen("input.txt", "r", stdin);
  86. int nn;
  87. scanf("%d", &nn);
  88. for(int i=1; i<=nn; i++){
  89. scanf("%d", &n);
  90. for(int j=0; j<n; j++)scanf("%d", &inp[i]);
  91. vector<st> vc;
  92. vc.push_back(st(inp[0], inp[0]));
  93. vector<point>pt;
  94. pt.push_back(point(inp[0], inp[0]));
  95. mans = 99999999;
  96. fnc(1, vc, pt, inp[0]*2.0);
  97. printf("Case 1: %lf\n", mans);
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement