http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D

改了N多次之后终于A了,一直在改判断正方形和矩形那,判断正方形时算出六条边再排序,若前四条边相等并且与后两条边满足勾股定理,说明是正方形,

判断矩形时,我先对结构体二级排序,这样四个点有确定的顺序,再用点积判断是否有三个角是直角,是的话就是矩形。

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct node
{
int x,y;
}point[]; int cmp(const struct node a,const struct node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
int dot(const struct node a, const struct node b,const struct node c, const struct node d)
{
int ans = (a.x-b.x)*(c.x-d.x) + (a.y-b.y)*(c.y-d.y);
if(ans == ) return ;
return ;
} int dis(const struct node a, const struct node b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int main()
{
while(~scanf("%d %d",&point[].x,&point[].y))
{
bool vis[] = {false};
for(int i = ; i <= ; i++)
scanf("%d %d",&point[i].x,&point[i].y);
int flag = ;
int cnt;
struct node t_point[];
for(int i = ; i <= ; i++)
{
for(int j = i+; j <= ; j++)
{
for(int k = j+; k <= ; k++)
{
for(int l = k+; l <= ; l++)
{
int distance[];
distance[] = dis(point[i],point[j]);
distance[] = dis(point[i],point[k]);
distance[] = dis(point[i],point[l]);
distance[] = dis(point[j],point[k]);
distance[] = dis(point[j],point[l]);
distance[] = dis(point[k],point[l]);
sort(distance,distance+);
if( distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
(distance[] + distance[] == distance[]))
{
flag = ;
vis[i] = true;
vis[j] = true;
vis[k] = true;
vis[l] = true;
break;
}
}
if(flag) break;
}
if(flag) break;
}
if(flag) break;
}
if(!flag)
printf("NO\n"); else
{
int tmp1[],tmp2[],t1 = ,t2 = ;
cnt = ;
for(int i = ; i <= ; i++)
{
if(!vis[i])
{
t_point[cnt++] = point[i];
tmp2[t2++] = i;
}
else tmp1[t1++] = i;
}
sort(t_point,t_point+cnt,cmp); if(dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]))
{
printf("YES\n");
for(int i = ; i < t1-; i++)
printf("%d ",tmp1[i]);
printf("%d\n",tmp1[t1-]);
for(int i = ; i < t2-; i++)
printf("%d ",tmp2[i]);
printf("%d\n",tmp2[t2-]);
}
else printf("NO\n"); } }
return ;
}

Rectangle and Square(判断正方形、矩形)的更多相关文章

  1. Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力

    B. Rectangle and Square 题目连接: http://codeforces.com/contest/135/problem/B Description Little Petya v ...

  2. bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*

    bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...

  3. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

    题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...

  4. [LeetCode] Valid Square 验证正方形

    Given the coordinates of four points in 2D space, return whether the four points could construct a s ...

  5. [LeetCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  6. matlab-霍夫变换详解(判断正方形长方形)

    霍夫变换 霍夫变换是1972年提出来的,最开始就是用来在图像中过检测直线,后来扩展能检测圆.曲线等. 直线的霍夫变换就是 把xy空间的直线 换成成 另一空间的点.就是直线和点的互换. 我们在初中数学中 ...

  7. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. [LeetCode] 221. Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  9. Rectangle and Square

    Description Little Petya very much likes rectangles and especially squares. Recently he has received ...

随机推荐

  1. RedHat7搭建Nginx+Apache+PHP

    Nginx做为前端服务器(本机IP:192.168.136.104),将访问PHP页面的动态请求转发给Apache服务器(只监听本地回环地址172.0.0.1:80) 安装Apache# yum -y ...

  2. PHP能得到你是从什么页面过来的,r…

    在开发web程序的时候,有时我们需要得到用户是从什么页面连过来的,这就用到了referer. 它是http协议,所以任何能开发web程序的语言都可以实现,比如jsp中是: request.getHea ...

  3. jquery判断div是否显示或者隐藏

    jquery判断div是否显示或者隐藏 很多时候会要判断一个div是不是显示着,没显示要怎么处理,显示的如何处理: 方法很简单,选择到你要判断的div,再用is(':hidden')判断是否隐藏:或者 ...

  4. viewpager在最后一页滑动之后,跳转到主页面

    [TOC] viewpager在最后一页滑动之后,跳转到主页面 思路 主要有是两个监听, 一是addOnPageChangeListener();二是setOnTouchListener(): add ...

  5. Java随机生成定长纯数字或数字字母混合数

    (转)Java随机生成定长纯数字或数字字母混合数 运行效果图: 具体实现代码

  6. easyui实现datagrid数字排序问题

    我们在使用easyui对列进行自动排序的时候(即顺序倒序),正常情况下是通过设置field中的sortable:true属性来控制是否可以排序.但是我们会发现一个有趣的问题,在对数字进行排序的时候,这 ...

  7. SQL,学习基础2

    列=字段, 记录=实体  事物日志文件(用来记录数据库的增删情况,扩展名LDF) 数据库文件(但是只有一个是主数据库文件(即用它来启动的),其余为次数据库文件)mdf 数据类型: 整形(整数)——in ...

  8. 【html】【4】html事件集合

    必看参考: http://www.runoob.com/tags/ref-eventattributes.html http://www.cnblogs.com/jiangchongwei/archi ...

  9. 一、C# 概述

    1.托管执行环境 2.程序集 3.关键字:C#保留字 4.除了C#定义的关键字之外,开发者可以提供他们自己的名称,编程语言将这些名称称为标识符 5.如果关键字包含一个"@"前缀,那 ...

  10. prmopt 提示框接收字符串,输入后按确定弹出警告框,警告内容为逆序的字符串

    虽然已经找到offer,但因为公司还没安排实习,所以在学校的时间多了很多.好吧,这段时间我用来备考四级啦(好悲催,还没过),然后这一天,闲着无聊,就帮妹妹看了这样子一道题目啦. 题目内容: 编制一个从 ...