Codeforces 1C Ancient Berland Circus
题意
给出一正多边形三顶点的坐标,求此正多边形的面积最小值。
分析
为了叙述方便,定义正多边形的单位圆心角 $u$ 为正多边形的某条边对该正多边形外心(外接圆的圆心)所张的角(即外接圆的某条弦所对的圆心角)。
- 多边形的边数未知,但其外接圆是确定的。多边形的外接圆即三个顶点所构成三角形的外接圆。面积最小即边数最少,单位圆心角最大。
- 设三角形某两边所对的圆心角为 $a_1$,$a_2$ (expressed in radians),则最大单位圆心角为 $u= \gcd(a_1, a_2, 2\pi-a_1-a_2)$
思路
- 三点定圆。两线段中垂线交点即为圆心。若线段AB两端点的坐标分别为 A $(x_1, y_1)$, B $(x_2, y_2)$,则AB的中垂线方程为 $$2(x_1-x_2) x + 2(y_1-y_2) y = (x_1^2+y_1^2) - (x_2^2+y_2^2)$$ 此式形式十分对称,便于记忆。解方程组即得圆心坐标。
- 求两正实数的最大公约数(gcd)。
- 求正多边形的面积。
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define dis2(p) (p.X*p.X+p.Y*p.Y)
#define det(i, j) (eq[0][i]*eq[1][j]-eq[0][j]*eq[1][i])
#define ang(p) atan2(p.Y, p.X)
#define eps 1e-4
#define PI 3.14159263558979323846
typedef double db;
typedef pair<db, db> P;
P p[];
//make sure that your algorithm is correct
db get_ang(P v1, P v2){
return acos((v1.X*v2.X+v1.Y*v2.Y)/dis2(v1));
}
P get_center(){
db eq[][];
for(int i=; i<; i++){
eq[i][]=*(p[i].X-p[i+].X);
eq[i][]=*(p[i].Y-p[i+].Y);
eq[i][]=dis2(p[i])-dis2(p[i+]);
}
return mp(det(, )/det(, ), det(, )/det(, ));
} P operator - (const P &a, const P &b){
return mp(a.X-b.X, a.Y-b.Y);
} db gcd(db a, db b){
return b<eps?a:gcd(b, fmod(a, b));
} int main(){
//freopen("in", "r", stdin);
for(int i=; i<; i++)
scanf("%lf%lf", &p[i].X, &p[i].Y);
P center=get_center();
P v[];
for(int i=; i<; i++)
v[i]=p[i]-center;
db a1=get_ang(v[], v[]);
db a2=get_ang(v[], v[]);
db a3=*PI-a1-a2;
db tmp=gcd(gcd(a1, a2), a3);
db res=PI/tmp*dis2(v[])*sin(tmp);
printf("%.8f\n", res);
return ;
}
P.S. 这道题还有更简便的解法,不必求外接圆圆心坐标,也不必求圆心角。有下列结论
设题中给出的三点所成三角形的三内角分别为 $A,B,C$ (expressed in radians) 则 $u$ 的最大值为
$$ 2 \gcd(A, B, C) $$
(此式与前面给出的表达式是一致的)
$A, B, C$ 可由余弦定理求得。还要求出三角形外接圆半径 $R$,可利用公式 $ R = \dfrac{abc}{4S}$,$a, b, c$ 为三边长,$S$ 为面积。
#include <bits/stdc++.h>
using namespace std; using ll=long long; ll pow(int x, int n, int mod){
ll res=;
for(; n; ){
if(n&) res*=x, res%=mod;
x*=x, x%=mod, n>>=;
}
return res;
} ll inv(int x, int p){
return pow(x, p-, p);
} ll lcm(ll x, ll y, int p){
return x*y%p*inv(__gcd(x, y), p)%p;
} int main(){
int n, k;
cin>>n>>k;
const int mod=1e9+; int res=; int m=min(*k, n);
k=min(k, n); for(int s=; s<<<m; s++){
int ones=;
for(int i=; i<m; i++)
ones+=bool(s&<<i);
int tmp=; if(ones==k){
for(int i=; i<m; i++)
if(s&<<i)
tmp=lcm(tmp, n-i, mod);
res=max(res, tmp);
}
}
cout<<res<<endl;
return ;
}
Codeforces 1C Ancient Berland Circus的更多相关文章
- codforces 1C Ancient Berland Circus(几何)
题意 给出正多边形上三个点的坐标,求正多边形的最小面积 分析 先用三边长求出外接圆半径(海伦公式),再求出三边长对应的角度,再求出三个角度的gcd,最后答案即为\(S*2π/gcd\),S为gcd对应 ...
- 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 ...
- 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 (几何)
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 1C (非原创)
C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...
随机推荐
- 28Spring_的事务管理_银行转账业务加上事务控制_基于注解进行声明式事务管理
将applicationContext.xml 和 AccountServiceImpl 给备份一个取名为applicationContext2.xml 和 AccountServiceImpl2.j ...
- 【转】【Thread】ReaderWriterLock 读写锁
ReaderWriterLock类 通常来讲,一个类型的实例对于并行的读操作是线程安全的,但是并行地更新操作则不是(并行地读和更新也不是). 这对于资源也是一样的,比如一个文件.当保护类型的实例安全时 ...
- 给 IIS Express 配置虚拟目录
使用 vs2015 打开旧项目,之前使用 iis 配置站点,然后在 vs 中附加 w3wp.exe 进行开发和调试的. 由于种种原因 iis 上配置站点各种失败. 之后发现,其实在 vs2015 中按 ...
- shell案例
调用同目录下的ip.txt内容: 路径 [root@lanny ~]# pwd /root txt文件 [root@lanny ~]# cat ip.txt 10.1.1.1 10.1.1.2 10. ...
- 添加web引用和添加服务引用有什么区别?
添加web引用和添加服务引用有什么区别,Add Service References 和 Add Web References 有啥区别?参考 http://social.microsoft.com/ ...
- 详解C# 迭代器[转]
迭代器模式是设计模式中行为模式(behavioral pattern)的一个例子,他是一种简化对象间通讯的模式,也是一种非常容易理解和使用的模式.简单来说,迭代器模式使得你能够获取到序列中的所有元素 ...
- 创建Spring容器
对于使用Spring的web应用,无须手动创建Spring容器,而是通过配置文件,声明式的创建Spring容器.在Web应用中,创建Spring容器有如下两种方式:1.直接在web.xml文件中配置: ...
- wifi使用的一些误区
下面是使用过程中的一些常用的误区: 家里买了三个路由器,信道都设置成同一个,这样会比较好. 买多个路由器的时候,一个人用的时候还好,多个人用的时候就会出问题. 多个设备在同样信道的时候会产生干扰.建议 ...
- HoloLens开发手记 - Unity之Locatable camera 使用相机
Enabling the capability for Photo Video Camera 启用相机能力 为了使用摄像头,我们必须启用WebCam能力. 在Unity中打开Player settin ...
- Mininet建立topology zoo中的拓扑
以前用Mininet建立拓扑都是在别人的代码上进行需求上的修改,这次从头开始将topology zoo(http://www.topology-zoo.org/)中的拓扑用Mininet建立,不失一般 ...