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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
using namespace std; const int N=110; int num[N][N];
bool vis[N][N];
int n,up,down;
int dir[4][2]={
{0,1},
{1,0},
{0,-1},{-1,0}
}; bool ok(int tx,int ty){
if(tx>=1&&tx<=n&&ty>=1&&ty<=n){
if(num[tx][ty]>=down&&num[tx][ty]<=up&&!vis[tx][ty])
return true;
}
return false;
} bool dfs(int x,int y){
if(x==n&&y==n) return true;
vis[x][y]=true;
int tx,ty;
for(int i=0;i<4;i++){
tx=x+dir[i][0];
ty=y+dir[i][1];
if(ok(tx,ty)){
if(dfs(tx,ty)) return true;
}
}
return false;
} int main(){
while(scanf("%d",&n)!=EOF){
int r=-1,l=0,m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&num[i][j]);
r=max(num[i][j],r);
}
}
int maxl=r;
bool flag; int ans=r-l;
for(int i=0;i<=num[1][1];i++){
l=num[1][1]; r= maxl;
while(l<=r){
m=(l+r)/2;
up=m,down=i;
memset(vis,false,sizeof(vis));
if(dfs(1,1)){
ans=min(ans,up-down);
r=m-1;
}
else
l=m+1;
}
}
printf("%d\n",ans);
}
return 0;
}

  

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. python:sql建表语句转换为json

    第一种sql格式: CREATE TABLE prpcitem_car ( proposalno ) NOT NULL, itemno ,) NOT NULL, riskcode ) NOT NULL ...

  2. 计算工作日之后N天的日期

    1.假期实体类: package com.smics.date; import java.io.Serializable; import java.util.Date; public class Va ...

  3. ubantu下NiFi单节点安装部署

    第一步,首先下载安装包:http://nifi.apache.org/download.html,博主下载的是1.4.0版本,直接下载的是编译后的文件. 第二步:将压缩包上传到服务器相应目录下,并且解 ...

  4. 爬虫之Urllib库的基本使用

    官方文档地址:https://docs.python.org/3/library/urllib.html 什么是Urllib Urllib是python内置的HTTP请求库包括以下模块urllib.r ...

  5. HBase学习----windows10下使用eclipse搭建HBase的开发环境

    以下是我搭建HBase开发环境的一些心得(windows10) 0.安装JDK和eclipse和一个可用的HBase. 这步是最基础的,在此就不赘述了 1.创建一个java项目: 基础问题,不赘述. ...

  6. IEnumerable ICollection IList

  7. Unity3d 销毁

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

  8. vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题

    1.如何设置config中的内容 readonly:true,//只读模式wordCount:false,//是否开启字数统计enableAutoSave: false,//自动保存功能 重点:ena ...

  9. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...

  10. 【Oracle】审计

    1.审计的功能:监控用户在database 的 action (操作) 2.审计分类: 1) session :在同一个session,相同的语句只产生一个审计结果(默认) 2) access : 在 ...