传送门

题意

给出一正多边形三顶点的坐标,求此正多边形的面积最小值。

分析

为了叙述方便,定义正多边形的单位圆心角 $u$ 为正多边形的某条边对该正多边形外心(外接圆的圆心)所张的角(即外接圆的某条弦所对的圆心角)。

  1. 多边形的边数未知,但其外接圆是确定的。多边形的外接圆即三个顶点所构成三角形的外接圆。面积最小即边数最少,单位圆心角最大。
  2. 设三角形某两边所对的圆心角为 $a_1$,$a_2$ (expressed in radians),则最大单位圆心角为 $u= \gcd(a_1, a_2, 2\pi-a_1-a_2)$

思路

  1. 三点定圆。两线段中垂线交点即为圆心。若线段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)$$ 此式形式十分对称,便于记忆。解方程组即得圆心坐标。
  2. 求两正实数的最大公约数(gcd)。
  3. 求正多边形的面积。
 #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的更多相关文章

  1. codforces 1C Ancient Berland Circus(几何)

    题意 给出正多边形上三个点的坐标,求正多边形的最小面积 分析 先用三边长求出外接圆半径(海伦公式),再求出三边长对应的角度,再求出三个角度的gcd,最后答案即为\(S*2π/gcd\),S为gcd对应 ...

  2. AC日记——codeforces Ancient Berland Circus 1c

    1C - Ancient Berland Circus 思路: 求出三角形外接圆: 然后找出三角形三条边在小数意义下的最大公约数; 然后n=pi*2/fgcd; 求出面积即可: 代码: #includ ...

  3. Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何

    C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...

  4. 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 ...

  5. CodeForces - 1C:Ancient Berland Circus (几何)

    Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...

  6. C. Ancient Berland Circus(三点确定最小多边形)

    题目链接:https://codeforces.com/problemset/problem/1/C 题意:对于一个正多边形,只给出了其中三点的坐标,求这个多边形可能的最小面积,给出的三个点一定能够组 ...

  7. 「CF1C Ancient Berland Circus」

    CF第一场比赛的最后一题居然是计算几何. 这道题的考点也是比较多,所以来写一篇题解. 前置芝士 平面直角坐标系中两点距离公式:\(l=\sqrt{(X_1-X_2)^2+(Y_1-Y_2)^2}\) ...

  8. 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 ...

  9. codeforces 1C (非原创)

    C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...

随机推荐

  1. f2fs解析(五)什么叫做compacted summary

    f2fs中普通的summary是长这样的:每一个段的SSA block中,前半部分是这个段的SSA,然后对于HOT_DATA以及COLD_DATA段,存放是的是nat journal 和 sit jo ...

  2. 15Mybatis_输出类型

    输出类型分为两种:1.resultType          和         2.resultMap 接下来先讲解resultType: 使用resultType进行输出映射,只有查询出来的列名和 ...

  3. 17Spring_AOP编程(AspectJ)_AspectJ的注解编程

    前面的各种Aop编程,都是基于XML的,这篇文章讲的是把XML方式改为注解方式来做. Spring注解开发和xml开发所需要的包是一样的,所以只要把xml开发方式的包复制到以注解为开发方式的包的项目下 ...

  4. 浏览器默认样式(User Agent Stylesheet)

    原文:http://www.zjgsq.com/898.html 不同浏览器对于相同元素的默认样式并不一致,这也是为什么我们在CSS的最开始要写 * {padding:0;marging:0}: 不过 ...

  5. /etc/profile和~/.bash_profile的区别

    /etc/profile是全局的,是私有的 /etc/profile用于整个系统所有用户, ~/.bash_profile, ~/.profile和~/.bashrc 用于各个用户,这里的" ...

  6. 加密算法使用(三):用用BASE64

    采用Base64编码具有不可读性,即所编码的数据不会被人用肉眼所直接看到 package testEncrypt; import java.security.Key; import java.secu ...

  7. Jdeveloper 太慢 slowly

    https://blogs.oracle.com/shay/entry/is_your_jdeveloper_slow_it_sho http://bexhuff.com/2012/09/jdevel ...

  8. .NET获取不到js写的cookie解决方法

    今晚使用javascript设置一个来路的cookie,之后使用ASP.NET获取这个cookie值,发现ASP.NET获取不到JS设置的cookie值,真郁闷中,以下是JS写Cookie的代码: C ...

  9. 我们为什么需要DTO?

    看了几套源码,其中都有用到DTO,这篇文章主要来谈论一下DTO使用的场合及其带来的好处. 在传统的编程中,我们一般都是前台请求数据,发送到Webservice,然后WebService向数据库发出请求 ...

  10. LeetCode 笔记27 Two Sum III - Data structure design

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...