您的位置:首页 > 其它

uva 11186

2015-08-02 23:40 387 查看
题意:给出一个圆的半径r,默认圆心在(0,0),圆上的有n个点,给出每个点从x正半轴移到对应位置的角度(0~360),没有三点共线情况,任意三个点都可以组成一个三角形,问这些三角形的总面积。

题解:用了三层for暴力枚举三个点,然后面积用叉积计算,水过去了。大神是用容斥做的,这里讲的不错:http://blog.csdn.net/shimmer_/article/details/38613079

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
struct Point {
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;

double dcmp(double x) {
if (fabs(x) < eps)
return 0;
return x < 0 ? -1 : 1;
}
Vector operator + (const Point& A, const Point& B) {
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (const Point& A, const Point& B) {
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (const Point& A, double a) {
return Vector(A.x * a, A.y * a);
}
Vector operator / (const Point& A, double a) {
return Vector(A.x / a, A.y / a);
}
double Cross(const Vector& A, const Vector& B) {
return A.x * B.y - A.y * B.x;
}
double Dot(const Vector& A, const Vector& B) {
return A.x * B.x + A.y * B.y;
}
double Length(const Vector& A) {
return sqrt(Dot(A, A));
}
bool operator < (const Point& A, const Point& B) {
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
bool operator == (const Point& A, const Point& B) {
return A.x == B.x && A.y == B.y;
}

//向量A旋转rad弧度,rad负值为顺时针旋转
Point Rotate(Point A, double rad) {
return Point(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
//角度转化弧度
double torad(double deg) {
return deg / 180.0 * PI;
}

const int N = 505;
int n;
double r;
Point P
;

int main() {
while (scanf("%d%lf", &n, &r) == 2 && n + r) {
double deg;
for (int i = 0; i < n; i++) {
scanf("%lf", °);
double rad = torad(deg);
P[i].x = r * cos(rad);
P[i].y = r * sin(rad);
}
double sum = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < n; k++)
sum += fabs(Cross(P[i] - P[j], P[i] - P[k])) * 0.5;
printf("%lld\n", (long long)(sum + 0.5));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: