博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最短路(数据处理):HDU 5817 Ice Walls
阅读量:4566 次
发布时间:2019-06-08

本文共 4633 字,大约阅读时间需要 15 分钟。

Have you ever played DOTA? If so, you may know the hero, Invoker. As one of the few intelligence carries, Invoker has 10 powerful abilities. One of them is the Ice Wall: Invoker generates a wall of solid ice directly in front of him, and the bitter cold emanating from it greatly slows nearby enemies and deals damage each second.
Now consider the map as a plane. You are now at point s, and want to move to point t. But Invoker has placed N ice walls on the map. Your moving speed is 1 per second, but you need k seconds to pass an ice wall. Time is precious, you must get to point t as quickly as possible. What's the minimum time you need?
For convenience, you can assume that all ice walls are segments (no width) either parallel to X-axis or to Y-axis. Segments are strictly disjoint (have no common point). Point s and t are not on any segment (have no common point).
You will not be slowed when pass the end point of a segment or walk along a segment.
 

Input

The input begins with an integer T, indicating the number of test cases. For each case, the first line is two integers N and k (1 <= N <= 500, 0 <= k <= 10^8), indicating the number of segments and the time needed to pass an ice wall. Next N lines, each have four integers x1, y1, x2, y2, indicating two end points of a segment, (x1, y1) and (x2, y2). Next line has two integers xs and ys, representing the coordinates of starting point s. The last line also has two integers xt and yt, representing the coordinates of target point t. For every point, |x| and |y| <= 
108.
 

Output

For each case, output one line containing the minimum time in second needed to get to t from s. The answer should be given within an absolute or relative error of 
106.
 

Sample Input

31 11 0 1 20 02 01 11 -2 1 20 02 01 31 -2 1 20 02 0

Sample Output

2.0000003.0000004.472136      这道题还是有些挑战的,可以一眼看出是最短路,但如何处理出点对的直接路径?   考虑极角排序,我不会,就用三角函数的sin和cos代替,然后用bit维护,可以做到N²logN。
1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 const double eps=1e-10; 8 const int N=1010,M=4000010; 9 10 struct Node{
int x,y,tp;}point[N],s,t,tmp; 11 struct Data{Node t;int id;double k,d;}st[N]; 12 int hsh[2*N],bit[2*N],csh,top;double G[N][N]; 13 14 double Dis(Node a,Node b){ 15 return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y)); 16 } 17 18 double K1(Node b){
return 1.0*(b.x-tmp.x)/Dis(tmp,b);} 19 double K2(Node b){
return 1.0*(b.y-tmp.y)/Dis(tmp,b);} 20 21 int Rk1(int tp){
return tp==4?1:tp==3?3:2;} 22 int Rk2(int tp){
return tp==2?1:tp==1?3:2;} 23 24 bool cmp1(Data p,Data q){ 25 Node a=p.t,b=q.t; 26 if(fabs(p.k-q.k)>0)return q.k-p.k>=eps; 27 if(a.tp==4&&b.tp==4)return q.d-p.d>=eps; 28 if(a.tp==3&&b.tp==3)return p.d-q.d>=eps; 29 return Rk1(a.tp)
0)return p.k
q.d; 37 return Rk2(a.tp)
dis[j])p=j; 92 vis[p]=true; 93 for(int j=1;j<=tot;j++) 94 dis[j]=min(dis[j],dis[p]+G[p][j]); 95 } 96 return dis[t]; 97 } 98 99 void Initial(){100 memset(G,0,sizeof(G));101 tot=csh=0;102 }103 104 int main(){105 scanf("%d",&T);106 while(T--){107 scanf("%d%d",&n,&ice);Initial();108 for(int i=1,x1,y1,x2,y2;i<=n;i++){109 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);110 hsh[++csh]=x1;hsh[++csh]=x2;111 hsh[++csh]=y1;hsh[++csh]=y2;112 if(x1==x2&&y1==y2)continue;113 if(x1==x2){114 if(y1>y2)swap(y1,y2);115 point[++tot]=(Node){x1,y1,1};116 point[++tot]=(Node){x2,y2,2};117 }118 if(y1==y2){119 if(x1>x2)swap(x1,x2);120 point[++tot]=(Node){x1,y1,3};121 point[++tot]=(Node){x2,y2,4};122 }123 }124 125 scanf("%d%d",&s.x,&s.y);126 scanf("%d%d",&t.x,&t.y);127 128 hsh[++csh]=s.x;hsh[++csh]=s.y;129 hsh[++csh]=t.x;hsh[++csh]=t.y;130 131 sort(hsh+1,hsh+csh+1);132 csh=unique(hsh+1,hsh+csh+1)-hsh-1;133 134 point[++tot]=(Node){s.x,s.y,0};135 point[++tot]=(Node){t.x,t.y,0};136 137 for(int i=1;i<=tot;i++)Solve1(i);138 for(int i=1;i<=tot;i++)Solve2(i); 139 140 for(int i=1;i<=tot;i++)141 for(int j=1;j<=tot;j++)142 G[i][j]+=Dis(point[i],point[j]);143 printf("%.6lf\n",Dij(tot-1,tot));144 }145 return 0;146 }

  WA在求dis的平方上了,注意会爆int。

附上数据生成器:

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 int G[1010][1010],h[1010]; 9 int main(){10 srand(time(NULL));11 int T=1,n=500,w=1000;12 printf("%d\n",T);13 while(T--){14 printf("%d %d\n",n,rand()%w);15 int x,y,a,b,l;16 for(int i=0;i

 

转载于:https://www.cnblogs.com/TenderRun/p/5991692.html

你可能感兴趣的文章
Cookie和Session的作用和工作原理
查看>>
字符串操作
查看>>
Visual Studio中改变environment 的布局和显示风格
查看>>
2016-XCTF Final-Richman
查看>>
文件下载
查看>>
extjs grid renderer用法
查看>>
vue 如何在循环中绑定v-model
查看>>
shell脚本
查看>>
[代码笔记]JS保持函数单一职责,灵活组合
查看>>
cmd 重定向
查看>>
【IOS开发】如何画1像素的线
查看>>
【计算机视觉】双目测距(五)--匹配算法对比
查看>>
KMP模板
查看>>
luogu 1314 聪明的质检员
查看>>
[转载]求职者防骗必读!楼主亲身经历告诉你岗前培训多么不靠谱而且违法!
查看>>
Hibernate内存溢出分析一例
查看>>
基于Axis1.4的webservice接口开发(接口调用)
查看>>
Hive内置函数详解
查看>>
【转】MyEclipse快捷键大全
查看>>
IT职业技能图谱10--Hadoop家族技能图谱
查看>>