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 ...
随机推荐
- Java中static作用及使用方法具体解释
1.1概述: static是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中不论什么变量或者代码都是在编译时由系统自己主动分配内存来存储的.而所谓静态就是指在编译后所分配的内存会一直存在.直到程序 ...
- web请求乱码问题总结
问题1:springmvc通过@ResponseBody向页面返回值(包括汉字)时,乱码 解决方案: springmvc3.2之后可以声明注解驱动器(不知道是不是这么翻译)的时候的控制编码的转换,结果 ...
- 院校-国外-美国:斯坦福大学( Stanford)
ylbtech-院校-国外-美国:斯坦福大学( Stanford) 斯坦福大学(Stanford University),全名小利兰·斯坦福大学(Leland Stanford Junior Univ ...
- quartz + spring 启动项目时,报错The web application [] appears to have started a thread named.........
只是想记录自己的错误信息,下次再出现就知道怎么操作,不用再查找资料 解决办法: package com.wqq.quartz_test.schedule; import javax.servlet.S ...
- Windows下Python + AutoCAD 多义线绘图小结
简介 在windows下台下, 使用comtypes库, 通过ActiveX操作autocad, 从而读取AutoCAD数据 comtypes.client AutoCAD ActiveX GetAc ...
- 【转】PowerDesigner物理数据表生成C#实体类Model
model实体类是什么: 在三层架构UI,BLL,DAL中,有时用户插入一条记录到数据库中,必然会有不少数据,按正常编程,也必然会一下子调用某个函数传入不少参数.为了减少参数的数量,达到高效简洁的效果 ...
- SQLServer int转float
例: select 2/4 会得到0 改为 select 2/4.0 则会得到0.500000 也同时达到了int转float的效果
- Unity3d Vector3
using UnityEngine; using System.Collections; public class test : MonoBehaviour { void Start () { Vec ...
- 第4章 部署模式 Deployment Plan(部署规划)
已开发了基于组件的应用程序,该应用程序在逻辑上构造为多层结构,如 Three-Layered Services Application. 中所述.您希望将它分布到一组在物理上为多级结构的服务器上,如 ...
- 单元测试之Mock
为什么需要Mock. 真实对象具有不确定的行为.所以会产生不可预测的结果. 真实对象很难被创建. 真实对象的某些行为很难被触发(如网络错误). 真实对象令程序的运行速度很慢. 真实对象有(或者是)用户 ...