2709: [Violet 1]迷宫花园
Time Limit: 5 Sec Memory Limit: 128 MB[ Submit][ Status][ Discuss]
Description
Input
Output
Sample Input
卡二分的sbt
这是A了的
double l = 0.0, r = 10.0;
while( r - l > eps ){
double mid = ( l + r ) / 2.0;
if( spfa( mid ) ) l = mid + eps;
else r = mid - eps;
}
WA了的while( r - l > eps ){
double mid = ( l + r ) / 2.0;
if( spfa( mid ) ) ans = l = mid;
else r = mid;
}
再也不做这种sbt了,浪费我时间
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <queue>
#include <ctime>
#include <map>
#include <set>
#define pa pair < int , int >
using namespace std;
#define eps 1e-10
int T, n, dx[4] = { 0, 0, 1, -1 },
dy[4] = { 1, -1, 0, 0 };
int r, c, sx, sy, tx, ty;
char a[105][105];
double Sum, dis[105][105], ans;
queue < pa > q; bool inq[105][105];
bool spfa( double dang ){
memset( dis, 127, sizeof(dis) );
memset( inq, 0, sizeof(inq) );
while( !q.empty() ) q.pop();
dis[sx][sy] = 0; q.push( make_pair( sx, sy ) ); inq[sx][sy] = 1;
while( !q.empty() ){
int xx = q.front().first, yy = q.front().second; q.pop(); inq[xx][yy] = 0;
for( int k = 0; k < 2; k++ ){
int xxx = xx + dx[k], yyy = yy + dy[k];
if( xxx > 0 && yyy > 0 && xxx <= r && yyy <= c && a[xxx][yyy] != '#' ){
if( dis[xxx][yyy] > dis[xx][yy] + 1.0 ){
dis[xxx][yyy] = dis[xx][yy] + 1.0;
if( !inq[xxx][yyy] ) q.push( make_pair( xxx, yyy ) ), inq[xxx][yyy] = 1;
}
}
}
for( int k = 2; k < 4; k++ ){
int xxx = xx + dx[k], yyy = yy + dy[k];
if( xxx > 0 && yyy > 0 && xxx <= r && yyy <= c && a[xxx][yyy] != '#' ){
if( dis[xxx][yyy] > dis[xx][yy] + dang ){
dis[xxx][yyy] = dis[xx][yy] + dang;
if( !inq[xxx][yyy] ) q.push( make_pair( xxx, yyy ) ), inq[xxx][yyy] = 1;
}
}
}
}
return dis[tx][ty] < Sum;
}
int main(){
scanf( "%d", &T );
while( T-- ){
memset( a, 0, sizeof(a) );
scanf( "%lf", &Sum ); scanf( "%d%d\n", &r, &c );
for( int i = 1; i <= r; i++ ){
gets(a[i] + 1);
for( int j = 1; j <= c; j++ ){
if( a[i][j] == 'S' ) sx = i, sy = j;
if( a[i][j] == 'E' ) tx = i, ty = j;
}
}
double l = 0.0, r = 10.0;
while( r - l > eps ){
double mid = ( l + r ) / 2.0;
if( spfa( mid ) ) ans = l = mid;
else r = mid;
}
printf( "%.5lf\n", ans );
}
return 0;
}