BC-Clarke and five-pointed star(水)
Clarke and five-pointed star
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geometric.
When he did a research with polygons, he found he has to judge if the polygon is a five-pointed star at many times. There are 5 points on a plane, he wants to know if a five-pointed star existed with 5 points given.
The first line contains an integer T(1≤T≤10)T(1 \le T \le 10)T(1≤T≤10),
the number of the test cases.
For each test case, 5 lines follow. Each line contains 2 real numbers xi,yi(−109≤xi,yi≤109)x_i, y_i(-10^9 \le x_i, y_i \le 10^9)xi,yi(−109≤xi,yi≤109),
denoting the coordinate of this point.
Two numbers are equal if and only if the difference between them is less than
10−410^{-4}10−4.
For each test case, print YesYesYes
if they can compose a five-pointed star. Otherwise, print NoNoNo.
(If 5 points are the same, print YesYesYes.
)
2
3.0000000 0.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557
3.0000000 1.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557
Yes
No
简单的判断是不是正五边形,就过。。。
官解:
容易看出只需要判断这5个点是否在一个正五边形上。
因此我们枚举排列,然后依次判断即可。
判定方法是,五条相邻边相等,五条对角线相等。
当然题目给的精度问题,窝只能说,如果泥做法不复杂,精度足够好的话,是可以过的。毕竟题目说的小于10−410^{-4}10−4是指理论上的,所以理论上适用所有的数之间的比较。所以有人问我开方前和开方后,我只能说,哪个精度高用哪个....
当然你也可以先求出凸包然后再判相邻距离......
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <stdio.h>
using namespace std; double x[10],y[10] ;
int main()
{
int T;
scanf("%d",&T);
double dis[10][10];
while(T--)
{
for(int i = 0 ; i < 5 ; i++){
scanf("%lf%lf",&x[i],&y[i]);
}
bool is = true;
// printf("---------------");
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
if(i==j)
continue;
else{
dis[i][j] = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
// printf("%lf ",dis[i][j]);
}
}
//printf("\n");
}
double mmax=dis[0][1],mmin = dis[0][1];
for(int i=2;i<5;i++){
if(mmax<dis[0][i]) mmax = dis[0][i];
if(mmin>dis[0][i]) mmin = dis[0][i];
}
for(int i=0;i<5;i++) ///其他距离
for(int j=0;j<5;j++){
if(i==j) continue;
if( fabs(dis[i][j]-mmin)>0.0001 && fabs(dis[i][j]-mmax)>0.00001)
is = false;
}
if(!is){
printf("No\n");
continue;
}
int adj[] = {-1,-1,-1,-1,-1}; ///相邻边距离
int coun = 0;
int i=0;
while(1){
if(coun == 5) break;
for(int j=0;j<5 && adj[i]==-1;j++){
if(i==j) continue;
if( fabs(dis[i][j]-mmin)<0.0001 ){
int k;
for(k=0;k<5;k++)
if(j==adj[k]) break;
if(k==5)
adj[i] = j,i=j,coun++;
}
}
}
for(i=0;i<5;i++)
if(adj[i]==-1)
is = false;
if(!is){
printf("No\n");
continue;
}
for(i=0;i<5;i++){ ///对角线距离
int adj1=adj[i],adj2;
for(int j=0;j<5;j++){
if(adj[j] == i){
adj2=j; break;
}
}
for(int j=0;j<5;j++){
if(j!=adj1&&j!=adj2&&j!=i){
if(fabs(dis[i][j]-mmax)>0.0001)
is = false;
}
}
}
if(!is){
printf("No\n");
continue;
}
printf("Yes\n");
}
return 0;
}
BC-Clarke and five-pointed star(水)的更多相关文章
- hdu 5563 Clarke and five-pointed star 水题
Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...
- [BC Round#26] Card 【各种水】
题目链接:HDOJ - 5159 这道题的做法太多了..BC的第二题也是可以非常水的.. 算法一 我在比赛的时候写的算法是这样的.. 预处理出所有的答案,然后对于每个询问直接输出. 询问 (a, b) ...
- SDOI(队列)
SDOI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Sub ...
- all unicode
Unicode Chart Range Decimal Name 0x0000-0x007F 0-127 Basic Latin 0x0080-0x00FF 128-255 Latin-1 Suppl ...
- 微信emoji的code
const MAP = [ "\xc2\xa9" => 'COPYRIGHT SIGN', "\xc2\xae" => ...
- hdu 5310(贪心)
题意:要买n个纪念品,单价p元,有团购价 m个q元,问怎样买钱最少 这个是BC周年庆第一题,水题昂,小学数学题,就是看n个纪念品单买.总体买团购然后零头买单价的.全部买团购价的多买也无所谓的,然后直接 ...
- SPOJ PHT【二分】+SPOJ INUM【最小/大值重复】
BC 两道其实都是水 没有完整地想好直接就码出事情.wa了一次以后要找bug,找完要把思路理的非常清楚 SPOJ PHT[二分] #include<bits/stdc++.h> using ...
- 线段树+离线 hdu5654 xiaoxin and his watermelon candy
传送门:点击打开链接 题意:一个三元组假设满足j=i+1,k=j+1,ai<=aj<=ak,那么就好的.如今告诉你序列.然后Q次询问.每次询问一个区间[l,r],问区间里有多少个三元组满足 ...
- 字体jquery ---
You don’t need icons! Here are 100+ unicode symbols that you can use Danny Markov December 3rd, 2014 ...
- QQ表情代码大全,你知道几个??
很久没有给大家分享代码了,今天趁着有点时间来给大家分享一下QQ空间的表情代码!不用感谢我,大家拿去用吧! [em]e100[/em] 微笑bai[em]e101[/em] 撇嘴[em]e102[/em ...
随机推荐
- zookeeper Keepalived
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...
- Mysqldump参数大全(转)
参数 参数说明 --all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , -Y ...
- windows下shopex农行支付接口开发笔记
1.首先是配置Java和tomcat 农行文档里的是linux下的说明.window下我们要按照以下在setclasspath.bat里设置JAVA_HOME,JRE_HOME(红色字体部分).设置这 ...
- 解决每次打开office 2010显示正在配置的问题
解决每次打开office 2010显示正在配置的问题 OFFICE 2010 MSDN版出来后,下载安装 ,启动后发现每次打开都会出现“正在配置”的进度,删除重装亦不成功,对SETUP.EXE改名也不 ...
- 【python】unittest中常用的assert语句
下面是unittest模块的常用方法: assertEqual(a, b) a == b assertNotEqual(a, b) a != b assertTrue(x) b ...
- LintCode "Sliding Window Median" & "Data Stream Median"
Besides heap, multiset<int> can also be used: class Solution { void removeOnly1(multiset<in ...
- 重复ID的记录,只显示其中1条
--重复ID的记录,只显示其中1条 --生成原始表 select * into #tempTable from ( select '1' as id ,'a' as name union all se ...
- jQuery formValidator使用入门
使用插件必须加载的文件 //加载jQuery类库 <script type="text/javascript" src="jquery-1.7.1.min.js&q ...
- oracle中一个字符串包含另一个字符串中的所有字符
oracle中一个字符串包含另一个字符串中的所有字符 --解决监理报告中所勾选的标段信息,与该用户所管理的标段字符串不匹配的问题. select * from a where instr(a,b)&g ...
- perl语言书籍教程推荐
互动出版网计算机频道.为您推荐关于perl语言的书籍教程.包括perl push.perl chomp以及perl python等perl语言内容. perl语言书籍一.<Perl语言编程 第四 ...