Circum Triangle UVA
来源:互联网 发布:qsv转换flv软件 编辑:程序博客网 时间:2024/06/10 08:00
题目链接:https://vjudge.net/problem/UVA-11186
题意:给定一个圆的半径,圆心为(0,0)。给定圆上n个点,圆上任意三个点比不共线,任意三点均可以组成三角形,求能组成的所有三角形的面积之和。
思路:直接n^3枚举所有的三角形,对面积求和即可;n^2容斥推理也可以,参考的是这个博客http://blog.csdn.net/shimmer_/article/details/38613079,讲得很清楚。
代码:
N^3复杂度:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<cstdlib>#include<sstream>#include<deque>#include<stack>#include<set>#include<map>using namespace std;typedef long long ll;typedef unsigned long long ull;const double eps = 1e-9;const int maxn = 10000 + 20;const int maxt = 300 + 10;const int mod = 10;const int dx[] = {1, -1, 0, 0};const int dy[] = {0, 0, -1, 1};const int Dis[] = {-1, 1, -5, 5};const double inf = 0x3f3f3f3f;const int MOD = 1000;const double PI = acos(-1.0);int n, m, k;int R;struct node{ double x, y; node(double x = 0.0, double y = 0.0) : x(x), y(y) {}};vector<node> v;double change(double q){ return q / 180.0 * PI;}double Len(node n1, node n2){//求两点之间距离 return sqrt((n1.x - n2.x) * (n1.x - n2.x) + (n1.y - n2.y) * (n1.y - n2.y));}double Area(double a, double b, double c){//已知三边求三角形面积 double p = (a + b + c) / 2.0; return sqrt(p * (p - a) * (p - b) * (p - c));}double dis[maxn][maxn];int main(){ while(~scanf("%d%d", &n, &R) && n && R){ v.clear(); memset(dis, 0, sizeof dis); double q; for(int i = 0; i < n; ++i){ scanf("%lf", &q); q = change(q); v.push_back(node((double)R * cos(q), (double)R * sin(q))); } for(int i = 0; i < n; ++i){//需要预处理一下,不然在n^3里求会超时 for(int j = 0; j < i; ++j){ dis[i][j] = dis[j][i] = Len(v[i], v[j]); } } double ans = 0.0; double len1, len2, len3; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ for(int k = j + 1; k < n; ++k){ ans += Area(dis[i][j], dis[i][k], dis[j][k]); } } } printf("%.0f\n", ans); } return 0;}
N^3复杂度:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<cstdlib>#include<sstream>#include<deque>#include<stack>#include<set>#include<map>using namespace std;typedef long long ll;typedef unsigned long long ull;const double eps = 1e-9;const int maxn = 10000 + 20;const int maxt = 300 + 10;const int mod = 10;const int dx[] = {1, -1, 0, 0};const int dy[] = {0, 0, -1, 1};const int Dis[] = {-1, 1, -5, 5};const double inf = 0x3f3f3f3f;const int MOD = 1000;const double PI = acos(-1.0);int n, m, k;int R;struct node{ double x, y; node(double x = 0.0, double y = 0.0) : x(x), y(y) {}};vector<node> v;double change(double q){ return q / 180.0 * PI;}double Area(double x1, double y1, double x2, double y2, double x3, double y3){//已知三角形三点坐标求三角形面积 return fabs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.0;}int main(){ while(~scanf("%d%d", &n, &R) && n && R){ v.clear(); double q; for(int i = 0; i < n; ++i){ scanf("%lf", &q); q = change(q); v.push_back(node((double)R * cos(q), (double)R * sin(q))); } double ans = 0.0; double len1, len2, len3; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ for(int k = j + 1; k < n; ++k){ ans += Area(v[i].x, v[i].y, v[j].x, v[j].y, v[k].x, v[k].y); } } } printf("%.0f\n", ans); } return 0;}N^2复杂度:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<cstdlib>#include<sstream>#include<deque>#include<stack>#include<set>#include<map>using namespace std;typedef long long ll;typedef unsigned long long ull;const double eps = 1e-9;const int maxn = 10000 + 20;const int maxt = 300 + 10;const int mod = 10;const int dx[] = {1, -1, 0, 0};const int dy[] = {0, 0, -1, 1};const int Dis[] = {-1, 1, -5, 5};const double inf = 0x3f3f3f3f;const int MOD = 1000;const double PI = acos(-1.0);int n, m, k;int R;double change(double q){ return q / 180.0 * PI;}double deg[maxn];int main(){ while(~scanf("%d%d", &n, &R) && n && R){ memset(deg, 0, sizeof deg); double q; for(int i = 0; i < n; ++i){ scanf("%lf", &q); deg[i] = change(q); } sort(deg, deg + n); double ans = 0; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ ans += (n + 2 * i - 2 * j) * sin(deg[j] - deg[i]);//看博客链接里的讲解很清楚 } } ans = ans * R * R / 2.0; printf("%.0f\n", ans); } return 0;}
阅读全文
0 0
- uva 11186 - Circum Triangle
- Circum Triangle - UVa 11186
- UVA - 11186-Circum Triangle
- Circum Triangle UVA
- UVA 11186(p349)----Circum Triangle
- Circum Triangle - UVa 11186 三角形面积
- uva 11186 - Circum Triangle(几何)
- UVa 11186 Circum Triangle 圆周上的三角形面积之和
- UVA 11186 - Circum Triangle(圆上三角形求法)
- UVA 11186 - Circum Triangle(计算几何+容斥)
- 习题10-39 UVA 11186 Circum Triangle圆周上的三角形
- UVa 488 Triangle Wave
- Uva 488 Triangle Wave
- UVa Triangle Wave
- UVA 488 - Triangle Wave
- uva-488 - Triangle Wave
- uva 11437 Triangle Fun
- UVA 11401 Triangle Counting
- unable to start within 450 seconds if the server reuires more time try increasing the timeout
- eclispe中使用 maven build启动maven项目和打包项目
- 第三章 -- 继承的概念
- ImportError: cannot import name IncompleteRead
- ssh-keygen的使用方法
- Circum Triangle UVA
- Linux下安装nginx
- 测试一下
- 剑指offer_把二叉树打印成多行+之字形
- sql常用的拆分和拼接函数
- 二分图
- redis 数据结构
- tf.get_variable 和tf.variable_scope
- win7 eclipse 调试spark