2251.cpp

来自「哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码」· C++ 代码 · 共 53 行

CPP
53
字号
/*  This Code is Submitted by wywcgs for Problem 2251 on 2006-05-29 at 10:22:42 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 128;
const int DIR[][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { 1, -1 }, 
						{ -1, 1 }, { -1, -1 } };
const double SM = 10000;
const double eps = 1e-4;
const double RATE = 1.5;

int w, h;
char map[N][N];
double m[N][N];

bool legal(int x, int y) { return x >= 0 && x < h && y >= 0 && y < w && map[x][y] == 's'; }

int main()
{
	int i, j, k, t, T;
	
	scanf("%d", &T);
	for(t = 0; t < T; t++) {
		scanf("%d %d\n", &h, &w);
		double pm = 0, tm = 0;
		for(i = 0; i < h; i++) {
			gets(map[i]);
			for(j = 0; j < w; j++)
				if(map[i][j] == 'b') m[i][j] = 0;
				else { m[i][j] = SM; pm += SM; }
		}
		for(i = 0; i < h; i++)
			for(j = 0; j < w; j++)
				if(map[i][j] != 'c') continue;
				else {
					for(k = 0; k < 8; k++) {
						int x = i+DIR[k][0], y = j+DIR[k][1];
						if(legal(x, y)) m[x][y] *= RATE;
					}
				}
		for(i = 0; i < h; i++)
			for(j = 0; j < w; j++) 
				if(map[i][j] == 's') tm += m[i][j];
		if(fabs(tm-pm) < eps) printf("Draw %.4lf\n", tm);
		else if(tm > pm) printf("Win %.4lf\n", tm-pm);
		else printf("Lose %.4lf\n", pm-tm);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?