⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2207.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2207 on 2006-04-18 at 12:01:59 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int SN = 12;
const double eps = 1e-3;

class Town {
private:
	int w, h, terrain[SN][SN];
	bool visible(double, double, double, double, double, double, bool) const;
public:
	bool see(double, double, double, double, double, double) const;
	void make();
};
void Town::make() {
	memset(terrain, 0, sizeof(terrain));
	int i, j; h = w = 10;
	for(i = 0; i < h; i++)
		for(j = 0; j < w; j++) scanf("%1d", &terrain[i][j]);
}
bool Town::see(double r1, double c1, double h1, double r2, double c2, double h2) const {
	return visible(r1, c1, h1, r2, c2, h2, true) && visible(c1, r1, h1, c2, r2, h2, false);
}
bool Town::visible(double x1, double y1, double h1, double x2, double y2, double h2, bool subx) const {
	if(fabs(x1-x2) < eps) return true;
	else if(x1 > x2) { swap(x1, x2); swap(y1, y2); }
	int xa = (int)floor(x1), xb = (int)ceil(x2);
	double dx = x2-x1, dy = y2-y1, dz = h2-h1;
	int cx;
	for (cx = xa+1; cx <= xb; cx++) {
		double ya = y1+dy/dx*(cx-x1), yb = y1+dy/dx*(cx-1-x1), z = h1+dz/dx*(cx-x1);
		int ry = (int)floor(ya), ry2 = (int)floor(yb);
		if(subx) {
			if (z < terrain[cx-1][ry] || z < terrain[cx][ry2]) return false;
		} else {
			if(z < terrain[ry][cx-1] || z < terrain[ry2][cx]) return false;
		}
	}
	return true;
}

int main()
{
	Town town;
	int t, T, i;
	
	scanf("%d", &T);
	for(t = 1; t <= T; t++) {
		town.make();
		double x, y, h; scanf("\n(%lf, %lf, %lf)", &x, &y, &h);
		printf("Fragfest City #%d\n", t);
		for(i = 0; i < 3; i++) {
			double px, py, ph; scanf("\n(%lf, %lf, %lf)", &px, &py, &ph);
			printf("Player %c is %s\n", i+'A', town.see(y, x, h, py, px, ph) ? "in sight" : "hiding");
		}
	}
	
	return 0;
}

⌨️ 快捷键说明

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