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 ...
随机推荐
- C#代码规范 .NET程序员需要提升的修养
一. 环境设置 首先去除VS开发环境中的一些选项如下: 粘贴时调整缩进 将类型的左大括号置于新行 将方法的左大括号置于新行 将匿名方法的左大括号置于新行 将控制块的左大括号置于新行 将“else” ...
- python-基础案例
范例一: 练习:元素分类 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值 ...
- VS的代码分析工具
来自:[译]Visual Studio 2008 Code Metrics http://www.cnblogs.com/live41/archive/2010/02/08/1665627.html ...
- jade 渲染js片段
script. str = !{JSON.stringify(val)}; res.render('wxpay', {val:result});
- [转]TortoiseSVN文件夹及文件图标不显示解决方法
FROM : http://blog.csdn.net/lishehe/article/details/8257545 由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的 ...
- linux命令细究
ls -ldahipFtr -t按照修改时间 -r翻转排序 /etc/profile 别名grep --color ls -pF ^$空行egrep -v "^#|^$&quo ...
- C语言 后缀自增的优先级详解
// ++ 后缀自增与取地址& ,提领 * (指针里的操作符)的优先级比较 #include<stdio.h> #include<stdlib.h> #include& ...
- python下RSA 加密/解密,签名/验证
基于win7 + python3.4 原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode() import rsa # 生成密钥 (pubkey, privk ...
- gunzip 和 unzip 解压文件到指定的目录
Linux 常用的压缩命令有 gzip 和 zip,两种压缩包的结尾不同:zip 压缩的后文件是 *.zip ,而 gzip 压缩后的文件 *.gz 相应的解压缩命令则是 gunzip 和 unzi ...
- LeetCode 笔记27 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...