Clarke and five-pointed star

Accepts: 237
Submissions: 591
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description

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.

Input

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)x​i​​,y​i​​(−10​9​​≤x​i​​,y​i​​≤10​9​​),
denoting the coordinate of this point.

Output

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.
)

Sample Input
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
Sample Output
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(水)的更多相关文章

  1. 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 ...

  2. [BC Round#26] Card 【各种水】

    题目链接:HDOJ - 5159 这道题的做法太多了..BC的第二题也是可以非常水的.. 算法一 我在比赛的时候写的算法是这样的.. 预处理出所有的答案,然后对于每个询问直接输出. 询问 (a, b) ...

  3. SDOI(队列)

    SDOI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Sub ...

  4. all unicode

    Unicode Chart Range Decimal Name 0x0000-0x007F 0-127 Basic Latin 0x0080-0x00FF 128-255 Latin-1 Suppl ...

  5. 微信emoji的code

    const MAP = [        "\xc2\xa9" => 'COPYRIGHT SIGN',        "\xc2\xae" => ...

  6. hdu 5310(贪心)

    题意:要买n个纪念品,单价p元,有团购价 m个q元,问怎样买钱最少 这个是BC周年庆第一题,水题昂,小学数学题,就是看n个纪念品单买.总体买团购然后零头买单价的.全部买团购价的多买也无所谓的,然后直接 ...

  7. SPOJ PHT【二分】+SPOJ INUM【最小/大值重复】

    BC 两道其实都是水 没有完整地想好直接就码出事情.wa了一次以后要找bug,找完要把思路理的非常清楚 SPOJ PHT[二分] #include<bits/stdc++.h> using ...

  8. 线段树+离线 hdu5654 xiaoxin and his watermelon candy

    传送门:点击打开链接 题意:一个三元组假设满足j=i+1,k=j+1,ai<=aj<=ak,那么就好的.如今告诉你序列.然后Q次询问.每次询问一个区间[l,r],问区间里有多少个三元组满足 ...

  9. 字体jquery ---

    You don’t need icons! Here are 100+ unicode symbols that you can use Danny Markov December 3rd, 2014 ...

  10. QQ表情代码大全,你知道几个??

    很久没有给大家分享代码了,今天趁着有点时间来给大家分享一下QQ空间的表情代码!不用感谢我,大家拿去用吧! [em]e100[/em] 微笑bai[em]e101[/em] 撇嘴[em]e102[/em ...

随机推荐

  1. 使用druid连接池的超时回收机制排查连接泄露问题

    在工程中使用了druid连接池,运行一段时间后系统出现异常: Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: ...

  2. eclipse注解——作者,创建时间,版本

    总结: /** * @author liangyadong * @date ${date} ${time} * @version 1.0 */

  3. MongoDB 启动mongo不带DB

    > mongo --nodb > conn = new Mongo("localhost:27017"); > db = conn.getDB("tes ...

  4. php发送ssl邮件

    <?php /** * 邮件发送类 * 支持发送纯文本邮件和HTML格式的邮件,可以多收件人,多抄送,多秘密抄送,带附件(单个或多个附件),支持到服务器的ssl连接 * 需要的php扩展:soc ...

  5. 多线程编程之Linux环境下的多线程(二)

    上一篇文章中主要讲解了Linux环境下多线程的基本概念和特性,本文将说明Linux环境下多线程的同步方式. 在<UNIX环境高级编程>第二版的“第11章 线程”中,提到了类UNIX系统中的 ...

  6. 理解javascript中的原型模式

    一.为什么要用原型模式. 早期采用工厂模式或构造函数模式的缺点:  1.工厂模式:函数creatPerson根据接受的参数来构建一个包含所有必要信息的person对象,这个函数可以被无数次的调用,工厂 ...

  7. winform 承载 WCF 注意,可能不是工作在多线程模式下

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMo ...

  8. HackerRank "The Indian Job"

    A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...

  9. activiti自定义流程之整合(二):使用angular js整合ueditor创建表单

    注:整体环境搭建:activiti自定义流程之整合(一):整体环境配置 基础环境搭建完毕,接下来就该正式着手代码编写了,在说代码之前,我觉得有必要先说明一下activit自定义流程的操作. 抛开自定义 ...

  10. 黄聪:MYSQL5.6缓存性能优化my.ini文件配置方案

    使用MYSQL版本:5.6 [client] …… default-character-set=gbk default-storage-engine=MYISAM max_connections=10 ...