设为首页 加入收藏

TOP

NYOJ10,skiing
2015-07-20 18:04:32 来源: 作者: 【 】 浏览:2
Tags:NYOJ10 skiing

skiing

时间限制:3000 ms | 内存限制:65535 KB 难度:5
描述
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子
1 2 3 4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
输入
第一行表示有几组测试数据,输入的第二行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。
后面是下一组数据;
输出
输出最长区域的长度。
样例输入
1
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
样例输出
25
来源
经典题目


import java.util.Arrays;
import java.util.Scanner;


public class NYOJ10_ieayoio {
	public static int [][]map;
	public static int [][]f;
	public static int []dx={0,1,0,-1,0};
	public static int []dy={0,0,-1,0,1};
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int t=input.nextInt();
		while (t-->0){
			int n=input.nextInt();
			int m=input.nextInt();
			map=new int [n+5][m+5];
			for (int i=0;i
      
       map[xx][yy]){
				int comway=1+dfs(xx,yy);
				if (f[x][y]
       
        map[x+dx[1]][y+dy[1]]) flag=true; if (map[x][y]>map[x+dx[2]][y+dy[2]]) flag=true; if (map[x][y]>map[x+dx[3]][y+dy[3]]) flag=true; if (map[x][y]>map[x+dx[4]][y+dy[4]]) flag=true; return flag; } } 
       
      


挺高兴的一直感觉没把握做的题,做了两天,经过调试通过样例后,没想到一次性提交就过了


方法就是深搜,不过就是加了一个数组f[x][y],来保存点(x,y)可滑到最低点的最长距离,dfs(x,y)用来深搜这个距离,若f[x][y]已存在,则将函数的值直接返回为f[x][y],

isnoway函数式来判断点(x,y)是否可以向更低点滑行







<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力??
上一篇: POJ1258 基础最小生成树
下一篇: poj 2247 Humble Numbers
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<script> (function(){ var appid = 'cyrBEfE7C', conf = 'prod_830794cf494da8b808afb2994cfe0fee'; var doc = document, s = doc.createElement('script'), h = doc.getElementsByTagName('head')[0] || doc.head || doc.documentElement; s.type = 'text/java script'; s.charset = 'utf-8'; s.src = 'http://assets.changyan.sohu.com/upload/changyan.js?conf='+ conf +'&appid=' + appid; h.insertBefore(s,h.firstChild); window.SCS_NO_IFRAME = true; })()
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 4869 Turn the pokers 多校训.. 下一篇hdu 2066 一个人的旅行

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: