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. 车载凯立德导航地图更新以及DSA数据更新方法

    每年升级每次都去重新摸索,1年时间忘完了,遂决定把他写下来,我这就去实验,实验好了来补 第一步: 找最新的凯立德软件和地图版本号 方法:淘宝搜索, 例如:凯立德 2016,搜索结果会出现比如2016 ...

  2. SQL Server 日期的加减函数: DATEDIFF DATEADD

    SQL Server 日期的加减函数: DATEDIFF    DATEADD DATEDIFF: 返回跨两个指定日期的日期边界数和时间边界数, 语法:DATEDIFF ( datepart , st ...

  3. EL表达式-例子

    <%@page import="java.util.*"%> <%@page import="java.util.ArrayList"%> ...

  4. TTL电平和CMOS电平总结

    TTL电平和CMOS电平总结 1,TTL电平:          输出高电平>2.4V,输出低电平<0.4V.在室温下,一般输出高电平是3.5V,输出低电平是0.2V.最小输入高电平和低电 ...

  5. 剑指offer系列60---第一个只出现一次的字符

    [题目]在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符的位置. * 若为空串,返回-1.位置索引从0开始 * [思路]1 首先遍历字符串数组,添 ...

  6. CentOS生产机器禁止ROOT远程SSH登录

    方法一 很多站长拥有linux主机,不管是虚拟机还是实体机,一般我们远程连接的时候,都是用的ssh(SecureShell建立在应用层和传输层基础上的安全协议). 它默认的端口22,默认使用root也 ...

  7. item2,实现singleton模式

    单例模式? 只能实现一个实例的类成为单例. ============== muduo库中单例模式实现 #include<boost/noncopyable.hpp> //#include ...

  8. RabbitMQ介绍2 - AMQP协议

    这一节介绍RabbitMQ的一些概念,当然也是AMQP协议的概念.官方网站也有详细解释,包括协议的命令: http://www.rabbitmq.com/tutorials/amqp-concepts ...

  9. 【Java】PrettyTime

    package test; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.D ...

  10. JAVA 匿名对象

    /* 匿名对象: 没有名字的对象 匿名对象的使用方式之一: 当对对象方法只调用一次时,我们可以用匿名对象来完成,比较简化. 匿名对象的使用方式之二: 匿名对象可以被当做实参传递 */ class Ca ...