Advertisement
jeff69

Untitled

Feb 5th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define sc(a) scanf("%d",&a)
  4. #define scll(a) scanf("%I64d",&a)
  5. #define scs(a) scanf(" %s",a)
  6. #define scc(a) scanf(" %c",&a)
  7. typedef long double ld;
  8. const int MX = 1e2+6;
  9. const ld INF = 2e9+5;
  10. const long long MOD = 1e9+7;
  11.  
  12. int n;
  13. ld w[111],h[111],d[111];
  14. int k[111];
  15. ld l,u;
  16.  
  17.  
  18. bool swp(int &x,int &y){swap(x,y);return 1;}
  19. bool contain(int x,int y)
  20. {
  21. if(d[x]<=d[y]&&d[x]+h[x]>=d[y])return 1;
  22. if(d[x]<=d[y]+h[y]&&d[x]+h[x]>=d[y]+h[y])return 1;
  23. swap(x,y);
  24. if(d[x]<=d[y]&&d[x]+h[x]>=d[y])return 1;
  25. if(d[x]<=d[y]+h[y]&&d[x]+h[x]>=d[y]+h[y])return 1;
  26. return 0;
  27.  
  28. }
  29. ld seglength(int x,int y)
  30. {
  31. ld c=hypot(d[x]+h[x]-d[y],u-w[x]-w[y]);
  32. swap (x,y);
  33. c=min(c,hypot(d[x]+h[x]-d[y],u-w[x]-w[y]));
  34. return c;
  35. }
  36. ld f(int x,int y)
  37. {
  38. if(k[x]==k[y]||u-w[x]-w[y]<=0)
  39. {
  40. if(d[x]<d[y]||swp(x,y))
  41. {
  42. return max(d[y]-d[x]-h[x],(ld)0);
  43. }
  44. }
  45. if(contain(x,y)||contain(y,x))
  46. {
  47. return max(u-w[x]-w[y],(ld)0);
  48. }
  49. return seglength(x,y);
  50. }
  51.  
  52. priority_queue<pair<ld,int>> pq;
  53. ld dis[MX];
  54. bool vis[MX];
  55. void dij()
  56. {
  57. memset(vis,0,sizeof vis);
  58. while(!pq.empty())pq.pop();
  59. for(int i=0;i<n;i++)
  60. {
  61. pq.push({-1*d[i],i});
  62. dis[i]=d[i];
  63. }
  64. while(!pq.empty())
  65. {
  66. int nxt=pq.top().second;
  67. ld odis=-1*pq.top().first;
  68. // cout<<nxt<<' '<<odis<<endl;
  69. pq.pop();
  70. if(vis[nxt])continue;
  71. vis[nxt]=1;
  72. for(int i=0;i<n;i++)
  73. {
  74. if(i==nxt)continue;
  75. if(dis[i]<=odis+min(f(i,nxt),f(nxt,i)))continue;
  76. pq.push({-1*(odis+min(f(i,nxt),f(nxt,i))),i});
  77. dis[i]=odis+min(f(i,nxt),f(nxt,i));
  78. }
  79. }
  80. }
  81. int main()
  82. {
  83. freopen("street.in","r",stdin);
  84. int T;
  85. cin>>T;
  86. cout<<setprecision(6)<<fixed;
  87. while(T--)
  88. {
  89. cin>>n>>l>>u;
  90. for(int i=0;i<n;++i)
  91. {
  92. cin>>h[i]>>w[i]>>d[i]>>k[i];
  93. }
  94. dij();
  95. ld ans=l;
  96. //cout<<dis[0]<<endl<<d[0]<<' '<<f(0,0);
  97. for(int i=0;i<n;i++)
  98. {
  99. ans=min(ans,l-h[i]-d[i]+dis[i]);
  100. }
  101. cout<<ans<<endl;
  102. }
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement