因为只有1e5个点,所以直接离散化bfs就好

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <queue>
  4. #include <set>
  5. #include <map>
  6. #include <stack>
  7. #include <cstdlib>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <cmath>
  11. using namespace std;
  12. typedef long long LL;
  13. typedef pair<int,int>pii;
  14. const int N=1e5+;
  15. const int INF=0x3f3f3f3f;
  16. const int mod=;
  17. pii p[N],tmp;
  18. int dx[]={-,-,-,,,,,};
  19. int dy[]={-,,,-,,-,,};
  20. int head[N],tot,d[N],cnt;
  21. struct Edge{
  22. int v,next;
  23. }edge[*N];
  24. void add(int u,int v){
  25. edge[tot].v=v;
  26. edge[tot].next=head[u];
  27. head[u]=tot++;
  28. }
  29. queue<int>q;
  30. int get(int s,int t){
  31. while(!q.empty())q.pop();
  32. memset(d,-,sizeof(d));
  33. d[s]=;q.push(s);
  34. while(!q.empty()){
  35. int u=q.front();
  36. q.pop();
  37. if(u==t)return d[t];
  38. for(int i=head[u];~i;i=edge[i].next){
  39. int v=edge[i].v;
  40. if(d[v]==-)d[v]=d[u]+,q.push(v);
  41. }
  42. }
  43. return -;
  44. }
  45. int main(){
  46. int x1,x2,y1,y2,n,s,t;
  47. while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
  48. scanf("%d",&n);
  49. memset(head,-,sizeof(head)),cnt=tot=;
  50. for(int i=;i<=n;++i){
  51. int x,l,r;
  52. scanf("%d%d%d",&x,&l,&r);
  53. for(int j=l;j<=r;++j)
  54. ++cnt,p[cnt].first=x,p[cnt].second=j;
  55. }
  56. sort(p+,p++cnt);
  57. cnt=unique(p+,p++cnt)-p-;
  58. for(int i=;i<=cnt;++i){
  59. for(int j=;j<;++j){
  60. tmp.first=p[i].first+dx[j];
  61. tmp.second=p[i].second+dy[j];
  62. int pos=lower_bound(p+,p++cnt,tmp)-p;
  63. if(pos==cnt+||p[pos].first!=tmp.first||p[pos].second!=tmp.second)
  64. continue;
  65. add(i,pos);
  66. }
  67. }
  68. tmp.first=x1,tmp.second=y1;
  69. s=lower_bound(p+,p++cnt,tmp)-p;
  70. tmp.first=x2,tmp.second=y2;
  71. t=lower_bound(p+,p++cnt,tmp)-p;
  72. printf("%d\n",get(s,t));
  73. }
  74. return ;
  75. }

FZU2235 国王的出游 水题的更多相关文章

  1. 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  4. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  5. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  6. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  7. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  8. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  9. ACM水题

    ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...

随机推荐

  1. xml simpleXML_load_file(), simpleXML_load_string()

    xml.xml文件 <?xml version='1.0'?><man>    <att>        <name>lin3615</name& ...

  2. Aspose.Words 总结

    生成答题卡 try { string tempPath = @"D:\moban\ttt.doc"; //Open document and create Documentbuil ...

  3. 【转】C# Excel 导入到 Access数据库表(winForm版)

    /// <summary> /// 获取Excel文件 /// </summary> /// <param name="sender">< ...

  4. WPF中添加Ribbon遇到的问题

    很奇怪的说,当我新建WPF工程,添加RibbonControlsLibary.dll后会运行时会报错,System.Windows.Markup.XamlParseException.引发的异常信息为 ...

  5. JSON对象的stringify()和parse()方法

    1.stringify() ---- JavaScript对象序列化为JSON字符串 eg1. var book = {title: 'JS', authors: ['Van'], edition:3 ...

  6. Html盒子模型学习总结

    Html的盒子模型 1.总的来说Html元素可以分为两类:即块状元素和行内元素. 2.块状元素(Block)类型的元素可以设置Width和Height值属性,而行内(Inline)类型无效. 3.浏览 ...

  7. HTTP协议(4)

    HTTP  概括总结 方便以后使用.遗忘时有侧重点的去学习,方便查阅: 开始看到webservice 和restful 有些不理解 现在可以简单理解为 : webservice = http协议+XM ...

  8. uCOS-II任务的挂起和恢复

    函数描述 OSTaskSuspend() 功能描述:无条件挂起一个任务.调用此函数的任务也可以传递参数OS_PRIO_SELF,挂起调用任务本身.函数原型:INT8U OSTaskSuspend ( ...

  9. sencha touch json store

    js: Ext.define('MyApp.store.MyJsonStore', { extend: 'Ext.data.Store', requires: [ 'MyApp.model.Perso ...

  10. Java编程思想(2)之一切皆对象