POJ 3897 Maze Stretching
来源:互联网 发布:软件开发工具研究 编辑:程序博客网 时间:2024/05/16 07:23
题目大意:我们可以对地图的竖向进行压缩或则扩张。
让竖向移动一步的距离由一变成X。最后,问你将地图变成多少比例,
可以让压缩后的地图的最短。题目反正说的好含糊。开始就是直接BFS,找到最短的以后进行压缩。
WA到 我已刻入灵魂。
思路:既然是压缩之后。那么我们就要用二分先求出压缩率,再进行BFS。
然后又会出现这样的情况
终点 13
12.5
此时的压缩率是300%。所以12.5出列的话答案就是15.5.。但是13出列的话就是14.。所以最优解是13.。这样还是会丢失最优解。
所以就用A*。。。让估价值低的先出列。
#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <cmath>#define eps 1e-6#define INF 0x3f3f3f3fusing namespace std;int dx[] = {-1,1,0,0};int dy[] = {0,0,-1,1};int v[205][205];int n;double l;struct node{ int x,y; double step; double dis; bool operator < (const node &a)const { return dis > a.dis; }};char map[205][205];int tagx,tagy;bool is_ok(int xx,int yy){ if(xx>=0 && xx<n && yy<strlen(map[xx]) && yy>=0) return true; return false;}double getdis(node t,double kp){ return fabs((double)tagx - t.x)*kp + fabs((double)tagy-t.y) + t.step;}double bfs(node t,double kp){ memset(v,0,sizeof(v)); priority_queue<node>Q; v[t.x][t.y]=0; node w,e; Q.push(t); while(!Q.empty()) { w=Q.top(); Q.pop(); for(int k=0;k<=3;k++) { e=w; int xx=e.x+dx[k]; int yy=e.y+dy[k]; if(k<=1) e.step=e.step + kp; else e.step = e.step + 1; if(e.step<v[xx][yy] && is_ok(xx,yy) && map[xx][yy]!='#') { e.x=xx; e.y=yy; e.dis = getdis(e,kp); v[xx][yy]=e.step; if(xx==tagx && yy==tagy) { return e.step; } Q.push(e); } } } return 0;}int main(){ node t; int TT; scanf("%d",&TT); int CASE=1; while(TT--) { scanf("%lf%d",&l,&n); getchar(); for(int i=0;i<n;i++) { gets(map[i]); for(int j=0;j<strlen(map[i]);j++) { if(map[i][j]=='S') { t.x=i; t.y=j; } else if(map[i][j]=='E') { tagx=i; tagy=j; } } } t.step=0; double left=0,right=10; double mid; //printf("bfs = %lf",bfs(t,0.5)); while(right - left > eps) { mid=(right + left) / 2; t.dis=getdis(t,mid); if(bfs(t,mid)>l) right=mid; else if(bfs(t,mid)<l)left= mid; else break; } printf("Case #%d: %.3f%%\n",CASE++,mid*100); } return 0;}
- POJ 3897 Maze Stretching
- poj 3897 Maze Stretching 二分+A*搜索
- poj 3897 Maze Stretching (二分+bfs+二维判重)
- poj-3897-Maze Stretching 二分+BFS+优先队列
- 【图论】【启发式搜索】【二分查找】[POJ 3897]Maze Stretching
- poj3897 Maze Stretching
- 【搜索】[POJ3897]Maze Stretching
- poj3897 Maze Stretching 二分+bfs
- [POJ3897] Maze Stretching (二分)(A*)
- POJ3897 Maze Stretching (二分+BFS)
- Maze Stretching Poj3897 二分+BFS
- #POJ3897#Maze Stretching(A* + 二分)
- POJ 1103 Maze
- poj 1103 maze源代码
- poj 3026 Borg Maze
- POJ 3026 Borg Maze
- POJ 3026 Borg Maze
- bfs poj 2157 maze
- Android 中对TextView文本多重点击-SpannableString
- /etc/profile和/root/.bash_profile有什么区别
- 【91xcz】XP下无法清空回收站怎么办
- windows开机自启动程序的位置
- iOS软键盘当被遮挡时,自动弹起,点击return时隐藏软键盘,点击外部UIView时,隐藏软键盘
- POJ 3897 Maze Stretching
- Distinct Subsequences
- ORA-02019的处理(转载于kasaur的个人空间http://space.itpub.net/25618347)
- putty中文乱码问题解决
- ASCII、Unicode和UTF-8之间的区别和联系
- Vector 的用法了解
- 获取SQL Server 2005-2008 获取一个表的结构
- nyoj 36 最长公共子序列
- Perl Hash用法之入门教程