codforces 1C Ancient Berland Circus(几何)
题意
给出正多边形上三个点的坐标,求正多边形的最小面积
分析
先用三边长求出外接圆半径(海伦公式),再求出三边长对应的角度,再求出三个角度的gcd,最后答案即为\(S*2π/gcd\),S为gcd对应的三角形的面积
注意如果三个点在同一段半圆弧上,需要thec=2*pi-thea-theb,而不能直接用acos()函数求
数据卡精度,gcd要取0.001才行,其他不行
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
const double pi = acos(-1.0);
double x1,x2,x3,y1,y2,y3;
double calc(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double work(double r,double x)
{
return (r*r*2-x*x)/(2*r*r);
}
double cal(double a,double b)
{
while(a-b>=-0.001) a-=b;return a;
}
double gcd(double a,double b)
{
if(b<=0.001) return a;
else return gcd(b,cal(a,b));
}
bool feq (double a, double b) {
return fabs(a-b) < 0.0001;
}
double fgcd(double a, double b) {
if (feq(a, 0)) return b;
if (feq(b, 0)) return a;
return fgcd(b, fmod(a, b));
}
int main()
{
cin>>x1>>y1>>x2>>y2>>x3>>y3;
double a=calc(x1,y1,x2,y2),b=calc(x1,y1,x3,y3),c=calc(x2,y2,x3,y3);
//printf("a=%f b=%f c=%f\n",a,b,c );
double p=(a+b+c)/2,S=sqrt(p*(p-a)*(p-b)*(p-c)),r=a*b*c/(4*S);
double cosa=work(r,a),cosb=work(r,b),cosc=work(r,c);
//printf("%f %f %f\n",cosa,cosb,cosc );
double thea=acos(cosa),theb=acos(cosb),thec=2*pi-thea-theb;//注意
//printf("%f %f %f\n", thea/(2*pi)*180,theb/(2*pi)*180,thec/(2*pi)*180);
double jiao=gcd(thea,gcd(theb,thec));
//printf("jiao=%f cnt=%f sin==%f\n",jiao/(2*pi)*180,cnt,sinn);
double ans=r*r*sin(jiao)/2*2*pi/jiao;
printf("%.6f\n", ans);
return 0;
}
codforces 1C Ancient Berland Circus(几何)的更多相关文章
- cf------(round)#1 C. Ancient Berland Circus(几何)
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...
- Codeforces 1C Ancient Berland Circus
传送门 题意 给出一正多边形三顶点的坐标,求此正多边形的面积最小值. 分析 为了叙述方便,定义正多边形的单位圆心角u为正多边形的某条边对其外接圆的圆心角(即外接圆的某条弦所对的圆心角). (1)多边形 ...
- AC日记——codeforces Ancient Berland Circus 1c
1C - Ancient Berland Circus 思路: 求出三角形外接圆: 然后找出三角形三条边在小数意义下的最大公约数; 然后n=pi*2/fgcd; 求出面积即可: 代码: #includ ...
- Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...
- CodeForces - 1C:Ancient Berland Circus (几何)
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...
- C. Ancient Berland Circus(三点确定最小多边形)
题目链接:https://codeforces.com/problemset/problem/1/C 题意:对于一个正多边形,只给出了其中三点的坐标,求这个多边形可能的最小面积,给出的三个点一定能够组 ...
- 「CF1C Ancient Berland Circus」
CF第一场比赛的最后一题居然是计算几何. 这道题的考点也是比较多,所以来写一篇题解. 前置芝士 平面直角坐标系中两点距离公式:\(l=\sqrt{(X_1-X_2)^2+(Y_1-Y_2)^2}\) ...
- Codeforces 1 C. Ancient Berland Circus-几何数学题+浮点数求gcd ( Codeforces Beta Round #1)
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
随机推荐
- JAVA_MyEclipse常见配置NETGEAR路由器如何设置
1 把宽带网线接到路由器的Internet口,然后用一个网线连接PC和路由器的任意端口(1,2,3,4一般四个),如下图所示 2 在浏览器地址栏中输入下面的网址,中途会弹出对话框询问账号密码,默认的账 ...
- Matlab依据样本随机数求概率曲线
相关Matlab函数:hist, bar, cdfplot, ksdensity (1) hist函数 n = hist(Y, x) 假设x是一个向量,返回x的长度个以x为中心的,Y的分布情况. 比 ...
- iOS APP第一次上架遇到的问题
现在苹果审核时越来越严了,我们有两个APP时同时上线的,代码用的也是一套的.但是有其中一个是第一次发布所以就拒了,信息就是下图.大概意思是用到支付了吗?用户是怎么来的.值需要把这些信息回复了.就OK ...
- Android实现RecyclerView的下拉刷新和上拉载入很多其它
需求 先上效果图, Material Design风格的下拉刷新和上拉载入很多其它. 源代码地址(欢迎star) https://github.com/studychen/SeeNewsV2 假设对于 ...
- HDU 6058 Kanade's sum 二分,链表
Kanade's sum Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th larg ...
- Writing a Discard Server
Netty.docs: User guide for 4.x https://netty.io/wiki/user-guide-for-4.x.html
- JSP JDBC 读取SQL Server 数据2
<%-- Created by IntelliJ IDEA. User: hellohongfu Date: 2017/12/21 Time: 0:16 To change this templ ...
- min-width 和 @media screen
min-width可以容器设置最小宽度,低于改宽度时,会自动加上滚动条,支持ie7及ie7+: @media only screen and (min-width: /*最小宽度(要加单位px)*/) ...
- box-sizing: border-box;的作用
box-sizing 属性可以被用来调整这些表现: content-box 是默认值.如果你设置一个元素的宽为100px,那么这个元素的内容区会有100px宽,并且任何边框和内边距的宽度都会被增加到 ...
- set built-in function
集合类型 集合对象是一组无序排列的可哈希的值,集合可以作为字典的键.因为集合是无序的,不可以为集合创建索引或执行切片操作,也没有键可以用来获取元素的值. 集合有两种不同的类型,可变集合和不可变集合.可 ...