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是在输入中给的,所 ...
随机推荐
- (三)Django模板语言
一.字典,列表,类在template模板中的使用 在视图函数中,即views.py中进行传值操作,可通过render方法,进行传值 from django.shortcuts import rende ...
- ocx控件的坑
前言 这还是第一次写博客,以前太懒了,现在发现是很有必要记录下这些经验和问题的.最近项目中有个需求(报表单据需要客户签名,连接签字板,把签名单据同步到服务器上),需要和硬件交互,当时硬件商提供了ocx ...
- BigInteger&BigDecimal类
BigInteger类 当需要处理超过 long 数值范围的大整数时,java.math 包中的 BigInteger 类提供任意精度的整数运算. 构造方式 //构造方法,将BigInteger的十进 ...
- Win7计划任务命令
计划任务命令 schtasks C:\Users\Administrator>schtasks /? SCHTASKS /parameter [arguments] 描述: 允许管理员创建.删除 ...
- 【转】提升你的Java应用性能:改善数据处理
提升你的Java应用性能:改善数据处理 作者:贾小骏 发布于07月26日 10:17 许多应用程序在压力测试阶段或在生产环境中都会遇到性能问题.如果我们看一下性能问题背后的原因,会发现很多是由数据处 ...
- C语言之枚举数据类型
枚举数据类型概述:1.枚举类型是C语言的一种构造类型.它用于声明一组命名的常数,2.当一个变量有几种可能的取值时,可以将它定义为枚举类型.3.枚举类型是由用户自定义的由多个命名枚举常量构成的类型,其声 ...
- vuex使用面板报 Unexpected token错误
Module build failed: SyntaxError: D:/frontend/webtest/src/components/mutations.vue: Unexpected token ...
- 关于爬虫的日常复习(8)—— 实战:request+正则爬取猫眼榜单top100
- ORM基础3 在python脚本里调用Django环境
1.查询 1.# all获取所有的object,结果QuerySet,列表 print('all'.center(80, '=')) ret = models.Person.objects.all() ...
- 【java面试】算法篇之堆排序
一.堆的概念 堆是一棵顺序存储的完全二叉树.完全二叉树中所有非终端节点的值均不大于(或不小于)其左.右孩子节点的值. 其中每个节点的值小于等于其左.右孩子的值,这样的堆称为小根堆: 其中每个节点的值大 ...