时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: G++;GCC

Description

Global warming is a big problem, isn't it? It is reported that the ice of Antarctica is melting. It results that oceans are glowing
and more and more places are flooded. Now the city of CODE and the city of ACM are in front of the problem though no wather seperate
the two cities. The situation will change with the ice continue melting. It is reported that the oceans glow P cm per year. The mayors
of the two cities want to know how many yeas there is before the two cities are seperated by water.
The map can be descriped as following

It is a M*N blocks
The city of CODE locates in the block of coordinate(1,1), the city of ACM locates in the block of coordinate(M,N). The altitude of
every blocks are given. It is guaranteed that the block of (1,1) and the block of (M,N) is higher than their neighbor block.
The following map shows the two cities weren't seperated by water.

The following map shows the two cities are eperated by water.

输入格式

The first line contains the two integer numbers N (1 <= N <= 500), M (1 <= M <= 500). Then N lines are following.
Each line contains
M integer numbers(seperated by a space). Each number no more than 1,000,000,000). The last line contains the integer number
P (1 <= P <= 1,000,000,000)

输出格式

The only line of the output contains the years mentioned above.

输入样例

3 3
9 5 7
4 6 8
8 3 9
1

输出样例

6

思路:以图中的最低海拔作为low,最高海拔作为high,二分一个值k,该值为能淹没部分区域并且把(1,1)和(n,m) 隔开的下界,那么答案即为 k/p 取上界。

其中用到dfs判断(1,1)和(n,m)两个点是否连通

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
typedef long long ll ;
const int INF = << ;
ll r[][] ;
int vis[][] ;
int dir[][] = {{-, },{, -},{, },{, }} ;
ll n, m, mx, mi, p ;
void dfs(int i, int j)
{
vis[i][j] = ;
for(int k = ; k < ; ++k)
{
int ti = i + dir[k][] ;
int tj = j + dir[k][] ;
if(ti < || ti > n || tj < || tj > m) continue ;
if(vis[ti][tj]) continue ;
dfs(ti, tj) ;
}
}
int go(int t)
{
memset(vis, , sizeof vis) ;
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j)
if(r[i][j] < t) vis[i][j] = ;
dfs(,) ;
if(vis[n][m]) return ;
else return ;
}
int solve()
{
int low = mi, high = mx ;
while(low < high)//二分
{ int m = (low + high) >> ;
//printf("[%d] ",m) ;
if(go(m)) high = m ;
else low = m + ;
}
return low ;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin) ;
#endif
mi = INF ; mx = -INF ;
scanf("%d%d",&n,&m) ;
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j){
scanf("%lld",&r[i][j]) ;
if(r[i][j] > mx) mx = r[i][j] ;
else if(r[i][j] < mi) mi = r[i][j] ;
}
// printf("%d %d\n",mi,mx) ;
scanf("%lld",&p) ;
int ans ;
ans = solve() ;
// printf("%d\n",ans) ;
if(ans % p == ) ans = ans / p ;
else ans = ans / p + ;
printf("%d\n",ans) ;
}

10324 Global Warming dfs + 二分的更多相关文章

  1. 【BZOJ4149】[AMPPZ2014]Global Warming 单调栈+RMQ+二分

    [BZOJ4149][AMPPZ2014]Global Warming Description 给定一个序列a[1],a[2],...,a[n].请从中选出一段连续子序列,使得该区间最小值唯一.最大值 ...

  2. uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)

    Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...

  3. [CEOI2018]Global warming

    [CEOI2018]Global warming 题目大意: 给定\(n(n\le2\times10^5)\),你可以将任意\(a_{l\sim r}(1\le l\le r\le n)\)每一个元素 ...

  4. BZOJ5442: [Ceoi2018]Global warming

    BZOJ5442: [Ceoi2018]Global warming https://lydsy.com/JudgeOnline/problem.php?id=5442 分析: 等价于后缀加(前缀减也 ...

  5. Java实现 LeetCode 655 输出二叉树(DFS+二分)

    655. 输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 行数 m 应当等于给定二叉树的高度. 列数 n 应当总是奇数. 根节点的值(以字符串格式给出)应当放在可放置的第一 ...

  6. hdu 5188 dfs+二分

    get了很多新技能 当时想到了用dfs,但是排序用的是限制时间排序,一直没搞出来. 正解: 二分用时,dfs判断,为了顺利进行做题,需要按照做题开始时间排序 还可以用dp 题意: 作为史上最强的刷子之 ...

  7. ACdream 1726 A Math game (dfs+二分)

    http://acdream.info/problem?pid=1726 官方题解:http://acdream.info/topic?tid=4246 求n个数里面能不能选一些数出来让它们的和等于k ...

  8. CH 2401 - 送礼 - [折半DFS+二分]

    题目链接:传送门 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了.某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_-b) ...

  9. 【AtCoder Grand Contest 007E】Shik and Travel [Dfs][二分答案]

    Shik and Travel Time Limit: 50 Sec  Memory Limit: 512 MB Description 给定一棵n个点的树,保证一个点出度为2/0. 遍历一遍,要求每 ...

随机推荐

  1. Oulipo(poj 3461)

    题意:求b这个字符串在a中出现的次数 这里不用KMP,用hash #include<cstdio> #include<iostream> #include<cstring ...

  2. 解决osg路径与文件名中的中文字符问题

    转至:http://blog.csdn.net/zhuqinglu/article/details/2064013 在打开或者保存一个osg模型的时候,经常遇到中文路径或者中文文件名的问题,此时会提示 ...

  3. NYOJ题目845无主之地1

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAKbCAIAAACIEYBGAAAgAElEQVR4nO3dvXKkPLe38X0Szn0gjv

  4. Android请求服务器的两种方式--post, get的区别

    android中用get和post方式向服务器提交请求_疯狂之桥_新浪博客http://blog.sina.com.cn/s/blog_a46817ff01017yxt.html Android提交数 ...

  5. 使用Asyncio的Coroutine来实现一个有限状态机

    如图: #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from ra ...

  6. NBU官方Doc網址https://www.veritas.com/support/en_US/article.DOC5332

    NBU(NetBackup) 7.0之後的版本官方文檔鏈接地址: https://www.veritas.com/support/en_US/article.DOC5332

  7. html5 svg 圆形进度条

    html5 svg 圆形进度条 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  8. 1-01Sql Sever 2008的安装

    Sql Sever 2008对计算机的配置要求: 1:处理器:最低1.4Ghz的处理器,建议使用2.0GHz或更高的处理器  . 2:内存:最小512MB, 建议使用1GB或更高的处理器. 3:磁盘容 ...

  9. 10gRAC运行srvctl报错error while loading shared libraries:

    数据库10g才会有这个错,因为11g的grid和oracle是分开的. [oracle@news01 orcl]$ srvctl /u01/app/oracle/db_1/jdk/jre/bin/ja ...

  10. SQLite密码添加移除

    背景:电脑清理--个人洁癖 SQLite的最原始的是没有加密的,从而衍生了多种加密算法,但在平常使用中使用System.Data.Sqlite,但其加密后,一般都需要要单独的sqlite管理器--像我 ...