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. TKinter事件及绑定

    Windows编程是基于消息的,绝大多数界面编程是基于事件的. 事件的绑定函数bind: 语法 :窗体对象.bind(事件类型,回调函数) 所谓的"回调函数",就是这个函数我们不用 ...

  2. HTML 打印 javascript连续打印 分页

    page-break-after属性介绍:http://www.w3school.com.cn/cssref/pr_print_page-break-after.asp <div style=& ...

  3. java通过ftp和sftp上传war包上传到Linux服务器实现自动重启tomcat的脚本代码

    ar包自动上传Linux并且自动重启tomcat 用的是jdk1.7出的文件监控 支持ftp和sftp,支持多服务器负载等 配置好config 非maven项目导入直接使用 #\u76D1\u542C ...

  4. HTML之布局position理解

    HTML中的布局,一个比较难以理解的概念,就是position了,W3C上的解释,position有如下几种: 1. static,默认值,也就是在样式中不指定position 2. fixed 3. ...

  5. [原]Fedora Linux环境下的应用工具总结

    一.办公类软件 1.Office办公:WPS 二.网络通信类软件 1.浏览器:Chrome 2.远程桌面:rdesktop(适用于Windows系列) 三.操作系统设置与优化 1.3D桌面管理:Com ...

  6. astats日志分析系统

    Awstats是一个免费非常简洁而且强大有个性的网站日志分析工具. 功能: 一:访问量,访问次数,页面浏览量,点击数,数据流量等 二:精确到每月.每日.每小时的数据 三:访问者国家 四:访问者IP 五 ...

  7. Java ArrayList操作

    import java.util.ArrayList; import java.util.List; import java.util.Iterator; public class Study { p ...

  8. 剑指offer系列32-----对称二叉树的判断

    [题目]请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. package com.exe7.offer; /** * [题目]请实现一个函 ...

  9. NOIP第7场模拟赛题解

    NOIP模拟赛第7场题解: 题解见:http://www.cqoi.net:2012/JudgeOnline/problemset.php?page=13 题号为2221-2224. 1.car 边界 ...

  10. 【转】T-SQL 教程

    USE [test] GO /****** Object: StoredProcedure [dbo].[PageIndex] Script Date: 12/07/2011 10:26:36 *** ...