pku2804.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 73 行

CPP
73
字号
#include <stdio.h>
#include <math.h>
#define elf 1e-9
struct Point
{
	double x, y, z;
};

Point p[4];
char m[10][11];

double min(double x, double y){return x < y ? x : y;}
double max(double x, double y){return x > y ? x : y;}

void init()
{
	int i, j;
	for (i = 0; i < 10; i++)
		scanf("%s", m[i]);
	for (i = 0; i < 4; i++)
	{
		scanf(" (%lf, %lf, %lf)", &p[i].y, &p[i].x, &p[i].z);
	}
}

int check(Point a, Point b)
{
	int i,j;
	double x, y, z;
	for (i = (int)ceil(min(a.x, b.x) + elf); i <= (int)floor(max(a.x, b.x) - elf); i++)
	{
		x = i;
		y = a.y + (b.y - a.y) * (x - a.x) / (b.x - a.x);
		z = a.z + (b.z - a.z) * (x - a.x) / (b.x - a.x);
		j = (int)y;
		if (z < m[i][j] - '0' || z < m[i-1][j] - '0')
			return 0;
	}
	for (j = (int)ceil(min(a.y, b.y) + elf); j <= (int)floor(max(a.y, b.y) - elf); j++)
	{
		y = j;
		x = a.x + (b.x - a.x) * (y - a.y) / (b.y - a.y);
		z = a.z + (b.z - a.z) * (y - a.y) / (b.y - a.y);
		i = (int)x;
		if (z < m[i][j] - '0' || z < m[i][j-1] - '0')
			return 0;
	}
	return 1;
}

void solve()
{
	int i;
	for (i = 1; i < 4; i++)
	{
		printf("Player %c is %s\n", 'A' + i - 1, check(p[0], p[i]) ? "in sight" : "hiding");
	}
}

int main()
{
	int t, T;
	scanf("%d", &T);
	for (t = 1; t <= T; t++)
	{
		init();
		printf("Fragfest City #%d\n", t);
		solve();
	}
	return 0;
}

⌨️ 快捷键说明

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