题目传送门

题意:中文题面

思路:

  先将所有题目给出的点离散化一下,得到一张n*m的网格,n和m最大都是400,所以我们只需要枚举每个加强的区域,将属于这个区域的边处理一下(所有横着的和竖着的边,暴力处理即可),然后相邻的点建边,建图,跑最短路即可。

  $mp[x][y][k]$表示网格上横坐标$x$纵坐标$y$,方向为k(0,1,2,3表示上右下左)这条离散化后长度为1的边被矩形覆盖的次数(初始值为1),时间就是离散化前的长度除以次数.然后建边跑dijkstra。

  比赛最后几分钟交了一发T了,发现离散化数组没排序就直接unique了,改完bug,bestcode就炸了。赛后补题,wa了两次,看着代码看了二十分钟,最后发现原来是oj没把题目搬完,交啥都是错的。。。搬完后就一发a了。。太伤心了。

  1. #include<bits/stdc++.h>
  2. #define rep(i,a,b) for(int i=a;i<=b;i++)
  3. #define dep(i,b,a) for(int i=b;i>=a;i--)
  4. #define clr(a,b) memset(a,b,sizeof(a))
  5. #define pb push_back
  6. #define pii pair<int,int >
  7. using namespace std;
  8. typedef long long ll;
  9. ll rd() {
  10. ll x=,f=;
  11. char ch=getchar();
  12. while(ch<''||ch>'') {
  13. if(ch=='-')f=-;
  14. ch=getchar();
  15. }
  16. while(ch>=''&&ch<='') {
  17. x=x*+ch-'';
  18. ch=getchar();
  19. }
  20. return x*f;
  21. }
  22. const int maxn=+;
  23. const int inf=0x3f3f3f3f;
  24. struct rc{
  25. ll x1,x2,y1,y2;
  26. }a[];
  27. double mp[][][];
  28. vector<ll >vx,vy;
  29. ll xa,ya,xb,yb,n,m,num;
  30. struct edge{
  31. int to;
  32. double w;
  33. friend bool operator<(const edge &a,const edge &b){
  34. return a.w>b.w;
  35. }
  36. };
  37. priority_queue<edge >q;
  38. vector<edge >ve[];
  39. int getid(int x,int y){
  40. return (y-)*n+x;
  41. }
  42. bool check(int x,int y){
  43. if(x<||x>n||y<||y>m)return false;
  44. return true;
  45. }
  46. double dis[];
  47.  
  48. void dij(){
  49. int px1=lower_bound(vx.begin(),vx.end(),xa)-vx.begin()+;
  50. int px2=lower_bound(vx.begin(),vx.end(),xb)-vx.begin()+;
  51. int py1=lower_bound(vy.begin(),vy.end(),ya)-vy.begin()+;
  52. int py2=lower_bound(vy.begin(),vy.end(),yb)-vy.begin()+;
  53. int id1=getid(px1,py1),id2=getid(px2,py2);
  54. // printf("id1:%d id2:%d n:%d m:%d px1:%d py1:%d px2:%d py2:%d\n",id1,id2,n,m,px1,py1,px2,py2);
  55. dis[id1]=;
  56. q.push({id1,});
  57. while(!q.empty()){
  58.  
  59. edge st=q.top();
  60. q.pop();
  61. int u=st.to;
  62. double w=st.w;
  63. // printf("u:%d w:%.4f\n",u,w);
  64.  
  65. int si=ve[u].size();
  66. rep(i,,si-){
  67. int v=ve[u][i].to;
  68. if(dis[v]>dis[u]+ve[u][i].w){
  69. dis[v]=dis[u]+ve[u][i].w;
  70. q.push({v,dis[v]});
  71. }
  72. }
  73. }
  74. printf("%.5f\n",dis[id2]);
  75. }
  76. int main(){
  77. int T;
  78. cin>>T;
  79. while(T--){
  80. cin>>num;
  81. vx.clear(),vy.clear();
  82. rep(i,,num){
  83. a[i].x1=rd();
  84. a[i].y1=rd();
  85. a[i].x2=rd();
  86. a[i].y2=rd();
  87. vx.pb(a[i].x1),vx.pb(a[i].x2);
  88. vy.pb(a[i].y1),vy.pb(a[i].y2);
  89. }
  90. cin>>xa>>ya>>xb>>yb;
  91. vx.pb(xa),vx.pb(xb);
  92. vy.pb(ya),vy.pb(yb);
  93. sort(vx.begin(),vx.end());
  94. sort(vy.begin(),vy.end());
  95. vx.erase(unique(vx.begin(),vx.end()),vx.end());
  96. vy.erase(unique(vy.begin(),vy.end()),vy.end());
  97. n=vx.size(),m=vy.size();
  98. rep(i,,n){
  99. rep(j,,m){
  100. rep(k,,)
  101. mp[i][j][k]=;
  102.  
  103. ve[getid(i,j)].clear();
  104. dis[getid(i,j)]=;
  105. }
  106. }
  107. rep(i,,num){
  108. int px1=lower_bound(vx.begin(),vx.end(),a[i].x1)-vx.begin()+;
  109. int px2=lower_bound(vx.begin(),vx.end(),a[i].x2)-vx.begin()+;
  110. int py1=lower_bound(vy.begin(),vy.end(),a[i].y1)-vy.begin()+;
  111. int py2=lower_bound(vy.begin(),vy.end(),a[i].y2)-vy.begin()+;
  112. rep(x,px1+,px2-){
  113. rep(y,py1+,py2-){
  114. mp[x][y][]++;
  115. mp[x][y][]++;
  116. mp[x][y][]++;
  117. mp[x][y][]++;
  118. }
  119. }
  120. rep(x,px1+,px2-){
  121. int y=py1;
  122. mp[x][y][]++;
  123. mp[x][y][]++;
  124. mp[x][y][]++;
  125. y=py2;
  126. mp[x][y][]++;
  127. mp[x][y][]++;
  128. mp[x][y][]++;
  129. }
  130. rep(y,py1+,py2-){
  131. int x=px1;
  132. mp[x][y][]++;
  133. mp[x][y][]++;
  134. mp[x][y][]++;
  135. x=px2;
  136. mp[x][y][]++;
  137. mp[x][y][]++;
  138. mp[x][y][]++;
  139. }
  140. mp[px1][py1][]++;
  141. mp[px1][py1][]++;
  142. mp[px1][py2][]++;
  143. mp[px1][py2][]++;
  144. mp[px2][py1][]++;
  145. mp[px2][py1][]++;
  146. mp[px2][py2][]++;
  147. mp[px2][py2][]++;
  148.  
  149. }
  150.  
  151. rep(i,,n){
  152. rep(j,,m){
  153. int id=getid(i,j);
  154. if(check(i-,j))ve[id].pb({getid(i-,j),(vx[i-]-vx[i-])/mp[i][j][]});
  155. if(check(i+,j))ve[id].pb({getid(i+,j),(vx[i]-vx[i-])/mp[i][j][]});
  156. if(check(i,j-))ve[id].pb({getid(i,j-),(vy[j-]-vy[j-])/mp[i][j][]});
  157. if(check(i,j+))ve[id].pb({getid(i,j+),(vy[j]-vy[j-])/mp[i][j][]});
  158.  
  159. }
  160. }
  161. dij();
  162. }
  163. }

2019 年百度之星·程序设计大赛 - 初赛一 C. Mindis 离散化+dijkstra的更多相关文章

  1. 2019 年百度之星·程序设计大赛 - 初赛一 C. HDU 6670 Mindis 离散化+dijkstra

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6670 Mindis Time Limit: 4000/2000 MS (Java/Others) M ...

  2. 2019 年百度之星·程序设计大赛 - 初赛一Game HDU 6669 (实现,贪心)

    Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  3. 2019 年百度之星·程序设计大赛 - 初赛四 1001 Strassen

    比赛链接:2019 年百度之星·程序设计大赛 - 初赛四 题目链接:HDU-6719 Strassen C++ 没写出来 于是直接上 Java 暴力. 好像可以用 __int128. import j ...

  4. Seq[找规律]----2019 年百度之星·程序设计大赛 - 初赛一:1005

    Seq Accepts: 1249 Submissions: 3956 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...

  5. 2019 年百度之星·程序设计大赛 - 初赛一 1005 Seq(数学规律)

    http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=861&pid=1005 Sample Input Sampl ...

  6. HDU6383 2018 “百度之星”程序设计大赛 - 初赛(B) 1004-p1m2 (二分)

    原题地址 p1m2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  7. HDU6380 2018 “百度之星”程序设计大赛 - 初赛(B) A-degree (无环图=树)

    原题地址 degree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  8. HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))

    度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

随机推荐

  1. 什么是CI/CD?

    CI, CD AND CD 当我们在谈论现代的软件编译和发布流程的时候,经常会听到CI 和CD这样的缩写短语.CI很容易理解,就是持续集成.但是CD既可以指代码持续交付,也可理解为代码持续部署.CI和 ...

  2. cm 安装cdh 后添加hive服务

    cm 安装cdh 后添加hive服务,出现错误提示 添加服务时候hive 配置如下: 错误信息提示: 错误日志: xec /opt/cloudera/parcels/CDH-5.4.7-1.cdh5. ...

  3. 重大利好,Dubbo 3.0要来了。

    关于Dubbo的好消息,2018年1月8日,Dubbo创始人之一梁飞在Dubbo交流群里透露了Dubbo 3.0正在开工的重大消息. Dubbo是阿里开源的分布式框架,已经多年停止更新处于半死不活状态 ...

  4. 高并发下的缓存架构设计演进及redis常见的缓存应用异象解决方案

    待总结 缓存穿透 缓存击穿 缓存雪崩等

  5. USACO2012 overplanting /// 矩阵切割 递归 oj21547

    题目大意: 在农场的任何一个“轴向对齐”的长方形区域(即垂直和水平方向)种植草坪. 现种植了N(1≤ N ≤10)个不同的矩形区域,其中一些甚至可能重叠. Input Multiple test ca ...

  6. 567. Permutation in String【滑动窗口】

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  7. (数据科学学习手札58)在R中处理有缺失值数据的高级方法

    一.简介 在实际工作中,遇到数据中带有缺失值是非常常见的现象,简单粗暴的做法如直接删除包含缺失值的记录.删除缺失值比例过大的变量.用0填充缺失值等,但这些做法会很大程度上影响原始数据的分布或者浪费来之 ...

  8. 在vue中使用高德地图开发,以及AMap的引入?

    百度引入BMap ,一个import 即可,可AMap 却报AMap is not difined ? 1.首先在 externals: { "BMap": "BMap& ...

  9. $router和$route的区别,路由跳转方式name 、 path 和传参方式params 、query的区别

    一.$router和$route的区别 $router : 是路由操作对象,只写对象$route : 路由信息对象,只读对象 例子://$router操作 路由跳转 this.$router.push ...

  10. vue之事件处理

    一.事件处理方法 1.格式 完整格式:v-on:事件名="函数名" 或 v-on:事件名="函数名(参数……)"  缩写格式:@事件名="函数名&qu ...