博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5652 二分加搜索 http://acm.split.hdu.edu.cn/showproblem.php?pid=5652
阅读量:4582 次
发布时间:2019-06-09

本文共 3407 字,大约阅读时间需要 11 分钟。

Problem Description
A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise up. With that at first the communation started to reduce and eventually died.
Let's assume from my crude drawing that the only way to reaching from India to China or viceversa is through that grid, blue portion is the ocean and people haven't yet invented the ship. and the yellow portion is desert and has ghosts roaming around so people can't travel that way. and the black portions are the location which have mountains and white portions are plateau which are suitable for travelling. moutains are very big to get to the top, height of these mountains is infinite. So if there is mountain between two white portions you can't travel by climbing the mountain.
And at each step people can go to 4 adjacent positions.
Our archeologists have taken sample of each mountain and estimated at which point they rise up at that place. So given the times at which each mountains rised up you have to tell at which time the communication between India and China got completely cut off.
 

 

Input
There are multi test cases. the first line is a sinle integer 
T which represents the number of test cases.
For each test case, the first line contains two space seperated integers N,M. next N lines consists of strings composed of 0,1 characters. 1 denoting that there's already a mountain at that place, 0 denoting the plateau. on N+2 line there will be an integer Q denoting the number of mountains that rised up in the order of times. Next Q lines contain 2 space seperated integers X,Y denoting that at ith year a mountain rised up at location X,Y.
T10
1N500
1M500
1QNM
0X<N
0Y<M
 

 

Output
Single line at which year the communication got cut off.
print -1 if these two countries still connected in the end.
Hint:
From the picture above, we can see that China and India have no communication since 4th year.
 

 

Sample Input
1 4 6 011010 000010 100001 001000 7 0 3 1 5 1 3 0 0 1 2 2 4 2 1
 

 

Sample Output
4
 
在hdu上提交的  一直wa  以为是过程有问题   最后发现数组开小了  一改就对了  自我感觉这是一道比较水的题  主要和二分挂钩    下面广搜来一波
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3f3f3f3f#define LL long long#define N 506char str[N][N];int w[N][N],aa[N*N],b[N*N],d,n,m;int a[4][2]= { {-1,0},{ 1,0},{ 0,1},{ 0,-1}};struct node{ int x,y;};int qq(int x,int y){ memset(w,0,sizeof(w)); queue
Q; node q,p; q.x=x; q.y=y; Q.push(q); w[x][y]=1; while(Q.size()) { p=Q.front(); Q.pop(); if(p.x==n-1)///表示可以到底 return 1; for(int i=0; i<4; i++) { q.x=p.x+a[i][0]; q.y=p.y+a[i][1]; int e=q.x,f=q.y; if(e>=0&&e
=0&&f

深搜也可以的

#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3f3f3f3f#define LL long long#define N 506char str[N][N];int w[N][N],aa[N],b[N],d,n,m;int a[4][2]= { {-1,0},{ 1,0},{ 0,1},{ 0,-1}};void qq(int x,int y){ if(d==1) return ; for(int i=0; i<4; i++) { int e=x+a[i][0]; int f=y+a[i][1]; if(e==n-1&&str[e][f]=='0') { d=1; return ; } if(e>=0&&e
=0&&f

 

转载于:https://www.cnblogs.com/a719525932/p/5789806.html

你可能感兴趣的文章
2016012032四则运算网页版结对项目报告
查看>>
淘宝专业版改基础版方法
查看>>
[转]ARM Pipeline
查看>>
[转]Blocking Code Injection on iOS and OS X
查看>>
颜色分类函数
查看>>
(中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。
查看>>
sort-归并排序
查看>>
django 快速实现完整登录系统(cookie)
查看>>
.NET中的out和ref关键字
查看>>
Python之ftp服务器
查看>>
KMP预处理
查看>>
oracle的wm_concat函数实现行转列
查看>>
C语 三子棋小游戏
查看>>
[BZOJ 1861] 书架
查看>>
送给毕业生的一个学习建议
查看>>
基于redis+lua实现高并发场景下的秒杀限流解决方案
查看>>
Oracle 块修改跟踪 (Block Change Tracking) 说明
查看>>
阿里云 Redis 服务遇到的问题
查看>>
Jwt Token 安全策略使用 ECDSA 椭圆曲线加密算法签名/验证
查看>>
Window2008通过web.config进行限制ip访问
查看>>