Recent Contest #2(Mar 25-Mar31, 2014)

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=43116#overview

H 水题不述。

#include 

using namespace std;

bool visit[10005];

int main() {
	int n;
	while (cin>>n) {
		memset(visit, 0, sizeof(visit));
		int num = -1, a;
		for (int i = 0; i <= n; i++) {
			cin>>a;
			if (visit[a]) {
				num = a;
			}
			else
				visit[a] = true;
		}
		cout << num << endl;
	}
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=42856#overview

D 久违了计算几何!!

就是一个凸包与圆的面积交的问题。

重点是建立抛物线的方程

Recent Contest #2(Mar 25-Mar31, 2014)_第1张图片

剩下的套模板就ok。

#include 
#include 
#include 

using namespace std;

struct Point {
	double x, y;
} p[105];

#define pi acos(-1.0)
#define eps 1e-10

double x_mult(Point sp, Point ep, Point op) {
	return (sp.x - op.x) * (ep.y - op.y) - (sp.y - op.y) * (ep.x - op.x);
}

double cross(Point a, Point b, Point c) {
	return (a.x - c.x) * (b.x - c.x) + (a.y - c.y) * (b.y - c.y);
}

double dist(Point a, Point b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

double cal_area(Point a, Point b, Point c, double r) {
	double A, B, C, x, y, tS;
	A = dist(b, c);
	B = dist(a, c);
	C = dist(b, a);
	if (A < r && B < r)
		return x_mult(a, b, c) / 2;
	else if (A < r && B >= r) {
		x = (cross(a, c, b) + sqrt(r * r * C * C - x_mult(a, c, b) * x_mult(a, c, b))) / C;
		tS = x_mult(a, b, c) / 2;
		return asin(tS * (1 - x / C) * 2 / r / B * (1 - eps)) * r * r / 2 + tS * x / C;
	}
	else if (A >= r && B < r) {
		y = (cross(b, c, a) + sqrt(r * r * C * C - x_mult(b, c, a) * x_mult(b, c, a))) / C;
		tS = x_mult(a, b, c) / 2;
		return asin(tS * (1 - y / C) * 2 / r / A * (1 - eps)) * r * r / 2 + tS * y / C;
	}
	else if (fabs(x_mult(a, b, c)) >= r * C || cross(b, c, a) <= 0 || cross(a, c, b) <= 0) {
		if (cross(a, b, c) < 0)
			if (x_mult(a, b, c) < 0)
				return (-acos(-1.0) - asin(x_mult(a, b, c) / A / B * (1 - eps))) * r * r / 2;
			else return (acos(-1.0) - asin(x_mult(a, b, c) / A / B * (1 - eps))) * r * r / 2;
		else return asin(x_mult(a, b, c) / A / B * (1 - eps)) * r * r / 2;
	}
	else {
		x = (cross(a, c, b) + sqrt(r * r * C * C - x_mult(a, c, b) * x_mult(a, c, b))) / C;
		y = (cross(b, c, a) + sqrt(r * r * C * C - x_mult(b, c, a) * x_mult(b, c, a))) / C;
		tS = x_mult(a, b, c) / 2;
		return (asin(tS * (1 - x / C) * 2 / r / B * (1 - eps)) + asin(tS * (1 - y / C) * 2 / r / A * (1 - eps))) * r * r / 2 + tS * ((y + x) / C - 1);
	}
}

int main() {
	double x, y, v, theta, t, g, R;
	while (cin >> x >> y >> v >> theta >> t >> g >> R) {
		if (x + y + v + theta + t + g + R < eps) break;
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> p[i].x >> p[i].y;
		}
		Point cir;
		cir.x = x + v * cos(theta / 180.0 * pi) * t;
		cir.y = y + v * sin(theta / 180.0 * pi) * t - 0.5 * g * t * t;
		double area = 0.0;
		for (int i = 0; i < n; i++) {
			area += cal_area(p[i], p[(i + 1) % n], cir, R);
		}
		cout << fixed << setprecision(2) <<  area << endl;
	}
}


你可能感兴趣的:(计算几何学)