给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上,矩形的行号从0到X-1,列号从0到Y-1再给出四个数字x1,y1,x2,y2,代表你要从点(x1,y1)移到(x2,y2)。在移动的过程中你当然希望离敌人的距离的最小值最大化,现在请求出这个值最大可以为多少,以及在这个前提下,你最少要走多少步才可以回到目标点。注意这里距离的定义为两点的曼哈顿距离,即某两个点的坐标分为(a,b),(c,d),那么它们的距离为|a-c|+|b-d|。

输入:

第一行给出数字N,X,Y

第二行给出x1,y1,x2,y2

下面将有N行,给出N个敌人所在的坐标

输出:

在一行内输出你离敌人的距离及在这个距离的限制下,你回到目标点最少要移动多少步。

Sample input

2 5 6

0 0 4 0

2 1

2 3

Sample output

2 14

  1. /*
  2. 同bzoj热身赛,二维前缀和,灌水留坑
  3. */
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<string>
  7. #include<cstring>
  8. #include<algorithm>
  9. #include<cmath>
  10. #include<queue>
  11. using namespace std;
  12. const int maxn = ,inf = ;
  13. inline int read(){
  14. char ch=getchar();
  15. int f=,x=;
  16. while(!(ch>=''&&ch<='')){if(ch=='-')f=-;ch=getchar();};
  17. while(ch>=''&&ch<=''){x=x*+(ch-'');ch=getchar();};
  18. return x*f;
  19. }
  20. struct nd{
  21. int x;
  22. int y;
  23. };
  24. int p,n,m;
  25. int ex[maxn],ey[maxn],xa,xb,ya,yb;
  26. int flag,dis[][],vis[][];
  27. short d[][],s[][];
  28. int dx[] = {,,-,};
  29. int dy[] = {,,,-};
  30. bool emy[][];
  31. inline bool jud(int x,int y,int t){
  32. if(x < || y < || x >= m || y >= n) return false;
  33. if(t == ) return true;
  34. t--;
  35. int tx=+x-y+t,ty=x+y+t,dx=+x-y-t,dy=x+y-t;
  36. if(ty>=n+m-) ty = n+m-;
  37. if(tx>=+m) tx = +m;
  38. int tot = s[ty][tx];
  39. if(dy>&&dx>-n) tot += s[dy-][dx-];
  40. if(dy>) tot -= s[dy-][tx];
  41. if(dx>-n) tot -= s[ty][dx-];
  42. if(tot) return false;
  43. else return true;
  44. }
  45. bool check(int t){
  46. if(!jud(xa,ya,t)) return false;
  47. flag++;
  48. for(int i = ;i <= n+;i++){
  49. for(int j = ;j <= m+;j++){
  50. dis[i][j] = inf;
  51. }
  52. }
  53. nd now,nxt;
  54. now.x = xa;
  55. now.y = ya;
  56. queue<nd> q;
  57. q.push(now);
  58. dis[ya][xa] = ;
  59. vis[ya][xa] = flag;
  60. while(!q.empty()){
  61. now = q.front();
  62. q.pop();
  63. //cout<<now.y<<" "<<now.x<<endl;
  64. for(int dr = ;dr < ;dr++){
  65. nxt.x = now.x + dx[dr];
  66. nxt.y = now.y + dy[dr];
  67. if(jud(nxt.x,nxt.y,t)&&vis[nxt.y][nxt.x] != flag){
  68. dis[nxt.y][nxt.x] = dis[now.y][now.x] + ;
  69. vis[nxt.y][nxt.x] = flag;
  70. q.push(nxt);
  71. if(nxt.y == yb && nxt.x == xb) return true;
  72. }
  73. }
  74. }
  75. return false;
  76. }
  77. int main(){
  78. freopen("escape.in","r",stdin);
  79. freopen("escape.out","w",stdout);
  80. cin>>p>>m>>n>>xa>>ya>>xb>>yb;
  81. for(int i = ;i <= p;i++){
  82. scanf("%d%d",&ex[i],&ey[i]);
  83. emy[ex[i]+ey[i]][+ex[i]-ey[i]] = true;
  84. }
  85. for(int i = ;i < n + m - ;i++){
  86. for(int j = -n;j < +m;j++){
  87. if(emy[i][j]) d[i][j] = d[i][j-] + ;
  88. else d[i][j] = d[i][j-];
  89. }
  90. }
  91. for(int i = ;i < n + m - ;i++){
  92. for(int j = -n;j < +m;j++){
  93. if(!i) s[i][j] = d[i][j];
  94. else s[i][j] = s[i-][j] + d[i][j];
  95. }
  96. }
  97. int l = ,r = n + m,mid,ans1,ans2;
  98. while(l <= r){
  99. mid = (l + r) >> ;
  100. if(check(mid)){
  101. ans1 = mid;
  102. ans2 = dis[yb][xb];
  103. l = mid + ;
  104. }else{
  105. r = mid - ;
  106. }
  107. }
  108. cout<<ans1<<" "<<ans2;
  109. return ;
  110. }

黄学长模拟day1 大逃亡的更多相关文章

  1. 黄学长模拟day1 某种密码

    关于某种密码有如下描述:某种密码的原文A是由N个数字组成,而密文B是一个长度为N的01数串,原文和密文的关联在于一个钥匙码KEY.若KEY=∑▒[Ai*Bi],则密文就是原文的一组合法密码. 现在有原 ...

  2. 黄学长模拟day1 球的序列

    N个编号为1-n的球,每个球都有唯一的编号.这些球被排成两种序列,分别为A.B序列,现在需要重新寻找一个球的序列l,对于这个子序列l中任意的两个球,要求j,k(j<k),都要求满足lj在A中位置 ...

  3. HDOJ 1429 胜利大逃亡(续)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. 胜利大逃亡(续)hdu1429(bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  5. hdu1429胜利大逃亡(bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  7. 胜利大逃亡[HDU1253]

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

  9. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

随机推荐

  1. 洛谷P1808 单词分类

    题目描述 Oliver为了学好英语决定苦背单词,但很快他发现要直接记住杂乱无章的单词非常困难,他决定对单词进行分类. 两个单词可以分为一类当且仅当组成这两个单词的各个字母的数量均相等. 例如“AABA ...

  2. Discuz X1.5 X2.5 X3 UC_KEY Getshell Write PHPCODE into config/config_ucenter.php Via /api/uc.php Vul

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 在Discuz中,uc_key是UC客户端与服务端通信的通信密钥.因此使用uc_k ...

  3. python模块

    模块介绍 为什么用模块 在代码量庞大的时候,如果靠一个脚本来进行函数式编程,对于脚本的可读性及后期脚本的维护带来极大的不便,而且无法分辨函数间的调用关系,所以,可以将一组功能类似的函数单独放在一个py ...

  4. POJ 2785 4 Values whose Sum is 0(想法题)

    传送门 4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 20334   A ...

  5. python bottle框架

    python bottle框架 简介: Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块. Bottl ...

  6. java编程思想-java中的并发(三)

    三.终结任务 1. 在阻塞时终结 线程状态 一个线程可以处于以下四种状态之一: 1)新建(new):当线程被创建时,他只会短暂的处于这种状态.此时,他已经分配了必须的系统资源,并执行了初始化.此刻线程 ...

  7. css中 Span 元素的 width 属性无效果原因及多种解决方案

    先运行下程序看下: <span style='width:300px;'>123</span> 输出:123 可以看到 span会自动根据包含的内容来变化宽度 这是因为:对于内 ...

  8. D/A转换器实验

    1.代码: #include<reg52.h>typedef unsigned char u8;typedef unsigned int u16;void delay (u16 num){ ...

  9. case when then else end

    1.根据数据库表中特定的值进行排序显示 select * from tablename where order by case when columname='' then 1 wnen column ...

  10. 自然语言22_Wordnet with NLTK

    QQ:231469242 欢迎喜欢nltk朋友交流 https://www.pythonprogramming.net/wordnet-nltk-tutorial/?completed=/nltk-c ...