时间限制: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. October 1st 2016 Week 40th Saturday

    Autumn, the year's last, loveliest smile. 秋,四季流转中的最后一抹,也是最美的那一抹微笑. I love autumn because it is the h ...

  2. Innodb之拷贝InnoDB表从一服务器到另一台服务器

    将Innodb类型的表从一台服务器拷贝到另一台服务器,或从一个库拷贝到另一个库. 前提是:innodb_file_per_table =ON. 1 先在目标服务器(库)上创建一个相同的表结构. 如: ...

  3. js函数的几个特殊点

    在ECMAScript中,Function(函数)类型实际上是对象.每个函数都是Function类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对象,因此函数名实际上也是一个指向函数对象 ...

  4. 按键消抖-----verilog

    实际系统中常用的按键大部分都是轻触式按键,如下图所示.该按键内部由一个弹簧片和两个固定触点组成,当弹簧片被按下,则两个固定触点接通,按键闭合.弹簧片松开,两个触点断开,按键也就断开了.根据这种按键的机 ...

  5. mysql的事务处理

    事务用于保证数据的一致性,它由一组相关的DML语句组成,该组的DML语句要么全部成功,要么全部失败. 示例: 银行账单 $mysqli=new mysqli("localhost" ...

  6. 微信公众平台中的openid是什么?

    在微信公众平台开发中,会遇到一个叫openid的东东,让我们这些不懂开发的摸不着头脑,开始我也是一头雾水,经过多方面查资料,终于明白是怎么回事了! openid是公众号的普通用户的一个唯一的标识,只针 ...

  7. Java 8新特性

    Java 8版本最大的改进就是Lambda表达式,其目的是使Java更易于为多核处理器编写代码:其次,新加入的Nashorn引擎也使得Java程序可以和JavaScript代码互操作:再者,新的日期时 ...

  8. saltapi中expr_form参数的使用

    以前,一直用compound参数, 现在,想要并行执行salt命令,那list就派上用场了. 同时传多个主机列表,用逗号分隔,然后,用list参数传,就好. [root@c1773 deployop] ...

  9. 【openGL】画直线

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...

  10. jQuery发送ajax请求

    利用jquery发送ajax请求的几个模板代码. $.ajax({ async : false, type: 'POST', dataType : "json", url: &qu ...