记录编号 395454 评测结果 AAAAA
题目名称 [NOIP 2001]Car的旅行路线 最终得分 100
用户昵称 Gravatarrewine 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2017-04-16 06:38:15 内存使用 1.60 MiB
显示代码纯文本
  1. #include <cstdio>
  2. #include <queue>
  3. #include <cmath>
  4. #define Rep(i,_z,_zz) for (int i = _z; i <= _zz; i++)
  5. struct pii{double x,y;void in() {scanf("%lf%lf",&x,&y);}}a[4000];
  6. double dis(pii a,pii b) {return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}
  7. pii calc(pii a,pii b,pii c) {return (pii){a.x+b.x-c.x,a.y+b.y-c.y};}
  8. void init(int k) {
  9. a[k].in();a[k+1].in();a[k+2].in();
  10. double ab = dis(a[k],a[k+1]),ac = dis(a[k],a[k+2]),bc = dis(a[k+1],a[k+2]),m = std::max(ab,std::max(ac,bc));
  11. if(ab == m) a[k+3] = calc(a[k],a[k+1],a[k+2]);
  12. if(ac == m) a[k+3] = calc(a[k],a[k+2],a[k+1]);
  13. if(bc == m) a[k+3] = calc(a[k+1],a[k+2],a[k]);
  14. };
  15. int tt[404],s,t,A,B; double f[404][404];
  16. double cost(int x,int y) {return (x-1)/4 == (y-1)/4?dis(a[x],a[y])*tt[(x-1)/4+1]:dis(a[x],a[y])*t;}
  17. void work() {
  18. scanf("%d%d%d%d",&s,&t,&A,&B);
  19. for (int i = 1; i <= s; i++) init((i-1)*4+1),scanf("%d",&tt[i]);
  20. int n = s<<2;double ans = 2147483647;
  21. Rep (i,1,n) Rep (j,1,n) f[i][j] = cost(i,j);
  22. Rep (k,1,n) Rep (i,1,n) if(k!=i) Rep (j,1,n)
  23. if(j!=k && j!=i) f[i][j] = std::min(f[i][j],f[i][k]+f[k][j]);
  24. Rep(i,(A-1)*4+1,(A-1)*4+4) Rep(j,(B-1)*4+1,(B-1)*4+4) ans = std::min(ans,f[i][j]);
  25. printf("%.1f\n",ans);
  26. }
  27. int main() {
  28. freopen("cardlxlx.in","r",stdin); freopen("cardlxlx.out","w",stdout);
  29. int n; for(scanf("%d",&n); n-- ;work());
  30. return 0;
  31. }