HDU4195 Regular Convex Polygon (正多边形、外接圆)
题意:
给你正n边形上的三个点,问n最少为多少
思路:
三个点在多边形上,所以三个点的外接圆就是这个正多边形的外接圆,余弦定理求出每个角的弧度值,即该角所对边的圆周角,该边对应的圆心角为圆心角的二倍。同时这个圆心角应为正多边形的每条边对应圆心角的整数倍,即2*pi/i的整数倍,遍历for i 1 to 1000 ,判断A*i/pi是否均为整数即可
坑点:
注意判断double是否为整数:return a-(int)(a+eps);
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 5e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); struct point{
double x, y;
point(double x = , double y = ):x(x), y(y){}
};
double length(point a, point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool ok(double a){
return a > &&fabs(a-(int)(a+eps)) < eps;
}
int main(){
point a, b, c;
while(scanf("%lf %lf", &a.x, &a.y) != ){
scanf("%lf %lf %lf %lf", &b.x, &b.y, &c.x, &c.y);
double ab = length(a, b);
double ac = length(a, c);
double bc = length(b, c);
double A = acos((ab*ab+ac*ac-bc*bc)/(2.0*ab*ac));
double B = acos((ab*ab+bc*bc-ac*ac)/(2.0*ab*bc));
double C = acos((ac*ac+bc*bc-ab*ab)/(2.0*ac*bc));
int flg = ;
for(int i = ; i <= ; i++){
if(ok(A*i/pi) && ok(B*i/pi) && ok(C*i/pi)){
flg = i;
break;
}
}
printf("%d\n", flg); }
return ;
}
HDU4195 Regular Convex Polygon (正多边形、外接圆)的更多相关文章
- HDU 4195 Regular Convex Polygon
思路:三角形的圆心角可以整除(2*pi)/n #include<cstdio> #include<cstring> #include<iostream> #incl ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- Leetcode: Convex Polygon
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- HOJ 13101 The Triangle Division of the Convex Polygon(数论求卡特兰数(模不为素数))
The Triangle Division of the Convex Polygon 题意:求 n 凸多边形可以有多少种方法分解成不相交的三角形,最后值模 m. 思路:卡特兰数的例子,只是模 m 让 ...
- ACM训练联盟周赛 G. Teemo's convex polygon
65536K Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo co ...
- 【LeetCode】469. Convex Polygon 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算向量夹角 日期 题目地址:https://leet ...
- Converting a Polygon ZM shape file to a regular Shape Polygon
from:http://blog.csdn.net/qb371/article/details/8102109 Locate the following tool - ArcToolbox > ...
- HUNAN 11562 The Triangle Division of the Convex Polygon(大卡特兰数)
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11562&courseid=0 求n边形分解成三角形的 ...
- HNU 13101 The Triangle Division of the Convex Polygon 组合数的因式分解求法
题意: 求第n-2个Catalan数 模上 m. 思路: Catalan数公式: Catalan[n] = C(n, 2n)/(n+1) = (2n)!/[(n+1)!n!] 因为m是在输入中给的,所 ...
随机推荐
- 用户svn密码自定义
由于在linux系统Apache+svn服务器,用户需要自定义密码怎么办呢? 1.创建脚本目录 mkdir -p /var/www/svn/svntools 2.创建apache配置文件 touch ...
- 扫描器是如何判定有xss漏洞的
这个问题,看似简单,实则触及到很多人的知识盲区 我们都知道,弹窗就能判定这个页面存在xss, 那么扫描器是怎么判断的呢,或者说扫描器是怎么判断是否弹窗的呢 测试发现 当响应的头中content-typ ...
- VUE CLI环境搭建文档
VUE CLI环境搭建文档 1.安装Node.js 下载地址 https://nodejs.org/zh-cn/download/ 2.全局安装VUE CLI win+R键打开运行cmd窗口输入一下代 ...
- Scala与Mongodb实践4-----数据库操具体应用
目的:在实践3中搭建了运算环境,这里学会如何使用该环境进行具体的运算和相关的排序组合等. 由数据库mongodb操作如find,aggregate等可知它们的返回类型是FindObservable.A ...
- cogs 1588. [USACO Feb04]距离咨询 倍增LCA
1588. [USACO Feb04]距离咨询 ★★ 输入文件:dquery.in 输出文件:dquery.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 农夫 ...
- Nginx配置文件模板
主配置文件nginx.conf user nginx; #设置nginx服务的系统使用用户 worker_processes 1; #工作进程数(和cpu核心数保持一致) error_log /var ...
- java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession
java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSessio ...
- C++内存管理与注意事项
内存是程序运行必不可少的资源,由操作系统分配和管理.作为程序员,我们通常做的只能是申请和归还.本文主要介绍C++内存的申请和释放(归还),以及注意事项. 1 申请和释放内存的运算符 申请 new 释放 ...
- Windows下安装Hadoop、Spark和HBase
1.Hadoop 安装Hadoop:下载hadoop-2.7.1.tar.gz,并解压到你想要的目录下,我放在D:\Library\hadoop-2.7.1. 配置Hadoop环境变量:HADOOP_ ...
- python,for循环的使用案例集
1.循环执行某一系列操作.将该操作定义为一个def,然后使用for去循环执行该操作 思路,先把操作定义为一个函数,在for循环执行这个函数 比如下面案例,把微信好友列表内的好友,循环的方式依次调整到第 ...