终于过了,SHIT,二分+DFS即可,二分区间,根据数字是否在区间内,变成迷宫题了。枚举第一个格子,二分上界,即可。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <climits>
  6. #include <string.h>
  7. #include <queue>
  8. #include <cmath>
  9. #include <vector>
  10. using namespace std;
  11.  
  12. const int N=110;
  13.  
  14. int num[N][N];
  15. bool vis[N][N];
  16. int n,up,down;
  17. int dir[4][2]={
  18. {0,1},
  19. {1,0},
  20. {0,-1},{-1,0}
  21. };
  22.  
  23. bool ok(int tx,int ty){
  24. if(tx>=1&&tx<=n&&ty>=1&&ty<=n){
  25. if(num[tx][ty]>=down&&num[tx][ty]<=up&&!vis[tx][ty])
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. bool dfs(int x,int y){
  32. if(x==n&&y==n) return true;
  33. vis[x][y]=true;
  34. int tx,ty;
  35. for(int i=0;i<4;i++){
  36. tx=x+dir[i][0];
  37. ty=y+dir[i][1];
  38. if(ok(tx,ty)){
  39. if(dfs(tx,ty)) return true;
  40. }
  41. }
  42. return false;
  43. }
  44.  
  45. int main(){
  46. while(scanf("%d",&n)!=EOF){
  47. int r=-1,l=0,m;
  48. for(int i=1;i<=n;i++){
  49. for(int j=1;j<=n;j++){
  50. scanf("%d",&num[i][j]);
  51. r=max(num[i][j],r);
  52. }
  53. }
  54. int maxl=r;
  55. bool flag; int ans=r-l;
  56. for(int i=0;i<=num[1][1];i++){
  57. l=num[1][1]; r= maxl;
  58. while(l<=r){
  59. m=(l+r)/2;
  60. up=m,down=i;
  61. memset(vis,false,sizeof(vis));
  62. if(dfs(1,1)){
  63. ans=min(ans,up-down);
  64. r=m-1;
  65. }
  66. else
  67. l=m+1;
  68. }
  69. }
  70. printf("%d\n",ans);
  71. }
  72. return 0;
  73. }

  

POJ 2110的更多相关文章

  1. POJ 2110 Mountain Walking 二分+bfs

    传送门 昨天看到这个题还以为是个脑残的dp, 然而脑残的是我. 题目意思就是从左上角走到右下角, 设x为路径上的最大值-最小值, 求x的最小值. 二分x, 对于每一个x, 枚举下界lower, low ...

  2. POJ 2110 二分+暴搜

    题意: 给你一个矩阵 ,你能往各个方向走(不走出去就行),每次只能上下左右走一格,问路径上的点权最大值和最小值的差最小是多少. 思路: 首先 二分最后的答案, 暴力枚举当前的区间是啥. DFS 就OK ...

  3. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. Java中static作用及使用方法具体解释

    1.1概述: static是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中不论什么变量或者代码都是在编译时由系统自己主动分配内存来存储的.而所谓静态就是指在编译后所分配的内存会一直存在.直到程序 ...

  2. web请求乱码问题总结

    问题1:springmvc通过@ResponseBody向页面返回值(包括汉字)时,乱码 解决方案: springmvc3.2之后可以声明注解驱动器(不知道是不是这么翻译)的时候的控制编码的转换,结果 ...

  3. 院校-国外-美国:斯坦福大学( Stanford)

    ylbtech-院校-国外-美国:斯坦福大学( Stanford) 斯坦福大学(Stanford University),全名小利兰·斯坦福大学(Leland Stanford Junior Univ ...

  4. quartz + spring 启动项目时,报错The web application [] appears to have started a thread named.........

    只是想记录自己的错误信息,下次再出现就知道怎么操作,不用再查找资料 解决办法: package com.wqq.quartz_test.schedule; import javax.servlet.S ...

  5. Windows下Python + AutoCAD 多义线绘图小结

    简介 在windows下台下, 使用comtypes库, 通过ActiveX操作autocad, 从而读取AutoCAD数据 comtypes.client AutoCAD ActiveX GetAc ...

  6. 【转】PowerDesigner物理数据表生成C#实体类Model

    model实体类是什么: 在三层架构UI,BLL,DAL中,有时用户插入一条记录到数据库中,必然会有不少数据,按正常编程,也必然会一下子调用某个函数传入不少参数.为了减少参数的数量,达到高效简洁的效果 ...

  7. SQLServer int转float

    例: select 2/4  会得到0 改为 select 2/4.0 则会得到0.500000 也同时达到了int转float的效果

  8. Unity3d Vector3

    using UnityEngine; using System.Collections; public class test : MonoBehaviour { void Start () { Vec ...

  9. 第4章 部署模式 Deployment Plan(部署规划)

    已开发了基于组件的应用程序,该应用程序在逻辑上构造为多层结构,如 Three-Layered Services Application. 中所述.您希望将它分布到一组在物理上为多级结构的服务器上,如 ...

  10. 单元测试之Mock

    为什么需要Mock. 真实对象具有不确定的行为.所以会产生不可预测的结果. 真实对象很难被创建. 真实对象的某些行为很难被触发(如网络错误). 真实对象令程序的运行速度很慢. 真实对象有(或者是)用户 ...