POJ 2110
终于过了,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的更多相关文章
- POJ 2110 Mountain Walking 二分+bfs
传送门 昨天看到这个题还以为是个脑残的dp, 然而脑残的是我. 题目意思就是从左上角走到右下角, 设x为路径上的最大值-最小值, 求x的最小值. 二分x, 对于每一个x, 枚举下界lower, low ...
- POJ 2110 二分+暴搜
题意: 给你一个矩阵 ,你能往各个方向走(不走出去就行),每次只能上下左右走一格,问路径上的点权最大值和最小值的差最小是多少. 思路: 首先 二分最后的答案, 暴力枚举当前的区间是啥. DFS 就OK ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- 解题报告 之 HDU5303 Delicious Apples
解题报告 之 HDU5303 Delicious Apples Description There are n apple trees planted along a cyclic road, whi ...
- [Plugin] 文件上传利器SWFUpload使用指南
SWFUpload是 一个flash和js相结合而成的文件上传插件,其功能非常强大.以前在项目中用过几次,但它的配置参数太多了,用过后就忘记怎么用了,到以后要用时又得 到官网上看它的文档,真是太烦了. ...
- IDEA中Lombok插件的安装与使用
背景 我们在开发过程中,通常都会定义大量的JavaBean,然后通过IDE去生成其属性的构造器.getter.setter.equals.hashcode.toString方法,当要对某个属性进行 ...
- Spring《八-一》CGLIB代理和自动代理
CGLIB代理 配置文档 <bean id="logProxy" class="org.springframework.aop.framework.ProxyFac ...
- Codeforces Round #453
Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...
- rem简单实现移动端适配
rem:移动web开发 默认字体大小是16px 在<html>中设置字体大小 与em的区别: em是在父级设置字体大小受影响 移动端适配 首先获取屏幕的宽度 计算当前屏幕宽度和640的比例 ...
- android随手记
Linearlayout: gravity:本元素中所有子元素的重力方向 layout_gravity:本元素对于父元素的重力方向 自定义权限:http://www.cnblogs.com/i ...
- 百度map API
1.做demo用的 http://developer.baidu.com/map/jsdemo.htm demo代码(外部使用的话需要提供密钥): <!DOCTYPE html> < ...
- css round corner div and transition
看stackoverflow上的圆角标签挺好看,自己动手试了下,用的属性是border-radius(即边框圆角半径,用px):加上transition effect,代码如下: <!DOCTY ...
- 我的wordpress在Nginx的配置
lnmp生成过程 You select the exist rewrite rule:/usr/local/nginx/conf/wordpress.conf Gracefully shutting ...