uva 11186
2015-08-02 23:40
387 查看
题意:给出一个圆的半径r,默认圆心在(0,0),圆上的有n个点,给出每个点从x正半轴移到对应位置的角度(0~360),没有三点共线情况,任意三个点都可以组成一个三角形,问这些三角形的总面积。
题解:用了三层for暴力枚举三个点,然后面积用叉积计算,水过去了。大神是用容斥做的,这里讲的不错:http://blog.csdn.net/shimmer_/article/details/38613079。
题解:用了三层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; }
相关文章推荐
- Android LeakCanary 内存检测Eclipes版本
- SQL Server 获取表的基本信息、字段列表、存储过程内容及参数列表
- nyoj42 一笔画问题 (欧拉回路)
- 我好像发现一个秘密。。
- Sublime Text 如何连接 FTP/SFTP
- 封装 数组库(简易)
- 本教程针对HBuilder5.0.0,制作日期2014-12-31(从HBuilder工具上获得)
- UE4信息交互-命令行执行自定义事件ConsoleCommand
- 本教程针对HBuilder5.0.0,制作日期2014-12-31(从HBuilder工具上获得)
- 一个栈,只提供push,pop,top,empty四种操作(这四种操作就是C++标准里的操作),对该栈的元素进行排序
- 【unity优化四】内存
- 杭电2073无限的路.水题
- 一步一步跟我学习hadoop(6)----hadoop利用FileSystem API 执行hadoop文件读写操作
- O-C相关-03:面向对象概念的具体介绍
- O-C相关-03:面向对象概念的具体介绍
- [Git 工作流指南]Git Workflows and Tutorials
- 【unity优化三】CPU
- brew命令
- HTML常用标记
- uboot里读sd卡内容