BZOJ 2709 Violet 1 迷宫花园
生活随笔
收集整理的這篇文章主要介紹了
BZOJ 2709 Violet 1 迷宫花园
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2709: [Violet 1]迷宮花園
Time Limit:?5 Sec??Memory Limit:?128 MBSubmit:?976??Solved:?340
[Submit][Status][Discuss]
Description
?
Input
Output
Sample Input
510.28 9 9
#########
# #
# # # # #
#S# #
##### # #
## # #
# ### ###
##E #
#########
4.67 9 9
#########
# ## ##
### #S# #
# # E ##
# # #####
# ## ###
# ##### #
# # #
#########
39.06 9 9
#########
# #
# # # # #
# E# # #
# # # # #
## ### #
# # #S# #
##### #
#########
24.00 9 9
#########
# ##
# # ## ##
# # ##
###S## E#
### # ##
# # # #
##### # #
#########
25.28 9 9
#########
# S##E# #
# ### # #
# ## #
# ## ###
# # ####
# # # ###
# #
#########
Sample Output
0.410004.67000
3.34000
5.00000
1.69000
HINT
?
?
Source
POJ 3897 Maze Stretching
實(shí)數(shù)二分+最短路判定
很水的一道題,注意讀數(shù)據(jù)的時(shí)候,空格scanf和cin會(huì)自動(dòng)忽略,用gets去讀
#include <bits/stdc++.h> #define ll long long #define eps 1e-7 using namespace std; inline int read(){int x=0;int f=1;char ch=getchar();while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}return x*f; } const int MAXN=1e4+10; struct node{int x,y; }e[MAXN]; const int dx[4]={0,0,-1,1}; const int dy[4]={-1,1,0,0}; int n,m,T,vis[MAXN],S,E; char ch[110][110]; double dis[MAXN],L; typedef pair < double,int > pii; priority_queue < pii,vector<pii>,greater<pii> > q; namespace zhangenming{inline int di(int xx,int yy){return (xx-1)*m+yy;}inline void dijsktra(double vv){for(int i=1;i<=n*m;i++){dis[i]=1e30;}memset(vis,0,sizeof(vis));while(!q.empty()) q.pop(); q.push(make_pair(0,S));dis[S]=0;while(!q.empty()){int tn=q.top().second;q.pop();if(vis[tn]) continue;vis[tn]=1;for(int i=0;i<4;i++){if(i>=2){int xx=e[tn].x+dx[i];int yy=e[tn].y+dy[i];if(yy==0||yy==m+1||ch[xx][yy]=='#') continue;if(dis[di(xx,yy)]>dis[tn]+vv){dis[di(xx,yy)]=dis[tn]+vv;q.push(make_pair(dis[di(xx,yy)],di(xx,yy)));}}else{int xx=e[tn].x+dx[i];int yy=e[tn].y+dy[i];if(xx==0||xx==n+1||ch[xx][yy]=='#') continue;if(dis[di(xx,yy)]>dis[tn]+1){dis[di(xx,yy)]=dis[tn]+1;q.push(make_pair(dis[di(xx,yy)],di(xx,yy)));}}}}}void work(){double l=0;double r=10;while((r-l)>eps){double mid=(l+r)*0.5;dijsktra(mid);if((L-dis[E])>-eps) l=mid;else r=mid;}dijsktra(r);if(dis[E]-L<=eps) printf("%.5lf\n",r);else printf("%.5lf\n",l);}void solve(){T=read();while(T--){scanf("%lf",&L);n=read();m=read();char c=getchar();for(int i=1;i<=n;i++){gets(ch[i]+1);for(int j=1;j<=m;j++){if(ch[i][j]=='S') S=di(i,j);if(ch[i][j]=='E') E=di(i,j);}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){e[(i-1)*m+j].x=i;e[(i-1)*m+j].y=j;}}work();}} } int main(){using namespace zhangenming;solve();return 0; }
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/something-for-nothing/p/8033606.html
總結(jié)
以上是生活随笔為你收集整理的BZOJ 2709 Violet 1 迷宫花园的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 区块链基础理论模拟试卷六
- 下一篇: 3.3 自动驾驶的安全结构(第三章 自动