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是在输入中给的,所 ...
随机推荐
- red note8 pro谷歌套件
谷歌核心Apps(即Google官方应用“全家桶”),包括YouTube,Google Now,Google Play store,Google Play Games,Google Maps等: 基于 ...
- [MariaDB]MHA高可用部署-实验
目录 一.简介 1.1MHA角色 二.MHA的工具 三.MHA部署过程 3.1.1 配置 3.1.2 环境规划 3.1.3 配置一主多从 3.2 MHA配置 3.2.1 master权限授予 3.2. ...
- Spring中Bean的实例化与DI的过程
引言 前文我们介绍了关于如何学习Spring的源码以及解析了spring中加载配置文件注册Beandefinition的过程.今天我们继续学习DI的过程. 创建实例和DI过程 IOC和DI都是对spr ...
- 小白学 Python 爬虫(38):爬虫框架 Scrapy 入门基础(六) Item Pipeline
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- redis最新版本安装及开机自启
的系统是ubuntu,安装方式有多种,一种是通过apt仓库,一种是下载源码,编译安装 1.通过apt仓库 具体命令: sudo apt-get update sudo apt-get install ...
- 对Java中可变参数的理解
说明 可变参数:是DK1.5之后出现的新特性,其实可变参数是0.1.2.3.....个参数的数组 使用前提 当方法的参数列表数据类型已经确定,但是参数的个数不确定,就可以使用可变参数 使用格式 修饰符 ...
- windows I/O设备
当外部设备连接到windows后,设备所连接到的集线器驱动程序将为设备分配硬件ID,然后Windows 使用硬件 Id 查找设备与包含设备驱动程序的驱动程序包之间最近的匹配项. 如果查找到,设备就可以 ...
- python如何计算程序(代码块)的运行时间?
1.引入time模块 2.调用time模块的time()函数 :用来获取当前的时间,返回的单位是秒 # 引入一个time模块, * 表示time模块的所有功能, # 作用: 可以统计程序运行的时间 f ...
- cogs 1963. [HAOI 2015] 树上操作 树链剖分+线段树
1963. [HAOI 2015] 树上操作 ★★★☆ 输入文件:haoi2015_t2.in 输出文件:haoi2015_t2.out 简单对比时间限制:1 s 内存限制:256 M ...
- 深入理解协程(四):async/await异步爬虫实战
本文目录: 同步方式爬取博客标题 async/await异步爬取博客标题 本片为深入理解协程系列文章的补充. 你将会在从本文中了解到:async/await如何运用的实际的爬虫中. 案例 从CSDN上 ...