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 ...
随机推荐
- LSB最低有效位隐写入门
LSB也就是最低有效位 (Least Significant Bit) 被替换成传递的信息字节.对原图影响很小. 这题可以算是隐写工具[wbStego]的使用入门练习题吧. 第一步,告诉你工具是支持在 ...
- Android Activity的生命周期
一.为什么要了解Activity的生命周期 activity is directly affected by its association withother activities, its tas ...
- action中result没有值
action中result没有值,访问action会输出action中的所有数据,输出类型为.action类型 .
- codevs 3012 线段覆盖 4 & 3037 线段覆盖 5
3037 线段覆盖 5 时间限制: 3 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 数轴上有n条线段,线段的两端都 ...
- Linux Linux程序练习八
题目:自己动手实现一个守护进程,当控制台窗口关闭时还可以在后台运行.每隔一秒钟向my.log文件中插入一条记录,记录格式如下:yyyy-mm-dd hh:mi:se 记录内容,其中yyyy为年,mm为 ...
- 本地环境,Ecshop安装教程
最近有个项目需要用ECshop来做,之前没接触过ECshop,今天去网上找了下安装教程,现在发出来分享一下. 1. ecshop网店系统最新版本是ECSHOP V2.7.3,去官网下载utf8和gbk ...
- JS实现星级评价
说明: 本方法采用了Jquery库,暂时检测兼容IE8版本.本示例的2种颜色的星星都是放入了一张png图片当中,当然还有其他的一些实现思路.本示例展示的情况是当前页面只有一个星级评价的情况. 思路: ...
- 20145234黄斐《信息安全系统设计基础》GDB调试汇编堆栈过程分析
堆栈跟踪 首先编辑一个程序 用gcc编译,再使用gdb调试,发现gdb尚未下载 下载后重新运行gdb 设置断点:b+行号或者"main" 运行:r frame:打印出的信息:栈的层 ...
- unity3d 扩展NGUI Tweener —— TweenFillAmount
好久没写博客了,上一篇是在今年上班之前写的 从年初到现在一篇没写过,每天都在加班,实在太忙了 上班半年多了,学到不少东西 今天分享一下刚写的小功能 TweenFillAmount 用过NGUI Twn ...
- [转]Android Studio 快捷键整理分享
Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码 ...