CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)
题目:http://codeforces.com/problemset/problem/135/B
题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形。
输出 第一行是正方形 ,第二行是矩形。
我的思路:用了4个for循环 枚举四个点, 用向量判断,四个点构成 六条边,如果这六条边里,
有四条边 与他们垂直的边有两个,就说明是矩形,在这个基础上,有 2条边 与他们垂直的边有一个。
说明是正方形。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std; struct point
{
int x,y;
} p[10];
int check(point a,point b,point c,point d)
{
int i,j,sumt=0,sumo=0;
int px[10],py[10];//代表6条边的 向量
int y[10];
memset(y,0,sizeof(y));
px[1]=a.x-b.x;
py[1]=a.y-b.y;
px[2]=a.x-c.x;
py[2]=a.y-c.y;
px[3]=a.x-d.x;
py[3]=a.y-d.y;
px[4]=b.x-c.x;
py[4]=b.y-c.y;
px[5]=b.x-d.x;
py[5]=b.y-d.y;
px[6]=c.x-d.x;
py[6]=c.y-d.y;
for(i=1; i<=6; i++)
{
for(j=i+1; j<=6; j++)
if((px[i]*px[j]+py[i]*py[j])==0)//判断垂直
{
y[i]++;
y[j]++;
}
}
for(i=1; i<=6; i++)
{
if(y[i]==2)
sumt++;//有2条边 与其垂直的个数
if(y[i]==1)
sumo++;//有1条边 与其垂直的个数
}
if(sumt==4&&sumo==2)
return 2;// 是正方形
if(sumt==4)
return 1;//是 矩形
return 0;//都不是
}
int main()
{
int i,j,k,l,ans,f,m;
int i2,j2,k2,l2;
int b[10],y;
while(cin>>p[1].x>>p[1].y)
{
f=0;
for(i=2; i<=8; i++)
cin>>p[i].x>>p[i].y;
for(i=1; i<=5; i++)
{
for(j=i+1; j<=6; j++)
{
for(k=j+1; k<=7; k++)
{
for(l=k+1; l<=8; l++)
{
ans=check(p[i],p[j],p[k],p[l]);
if(ans==0)
continue;
if(ans==2)//当前是正方形时
{
y=1;
for(m=1; m<=8; m++)
{
if(m!=i&&m!=j&&m!=k&&m!=l)
b[y++]=m;
}
i2=b[1];
j2=b[2];
k2=b[3];
l2=b[4]; ans=check(p[i2],p[j2],p[k2],p[l2]);//看是否 剩下的点是矩形
if(ans)
{
f=1;
break;
}
}
}
if(f)
break;
}
if(f) break;
}
if(f) break;
}
if(f)
{
cout<<"YES"<<endl;
printf("%d %d %d %d\n",i,j,k,l);
printf("%d %d %d %d\n",i2,j2,k2,l2);
}
else
cout<<"NO"<<endl;
}
return 0;
}
CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)的更多相关文章
- Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...
- 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 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}
C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...
- bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*
bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
- python3 turtle画正方形、矩形、正方体、五角星、奥运五环
python3 环境 turtle模块 分别画出 正方形.矩形.正方体.五角星.奥运五环 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:H ...
- Intersection--poj1410(判断线段与矩形的关系)
http://poj.org/problem?id=1410 题目大意:给你一个线段和矩形的对角两点 如果相交就输出'T' 不想交就是'F' 注意: 1,给的矩形有可能不是左上 右下 所以要先判 ...
随机推荐
- 【DELPHI】线程相关
//准备让线程调用的测试函数 procedure Draw(aCanvas: TCanvas; X,Y: Integer; aCount: Integer = 100000); var i: Inte ...
- ComboBox Control Messages 消息
连接到MSDN,有时间完善这个.具体说明可点击进入msdn CB_ADDSTRING 添加一个字符串组合框的列表框.如果组合框没有cbs_sort风格,字符串添加到列表的结尾.否则,该字符串插入列表, ...
- 解决 ListView 水平滚动条不出现的问题(转载)
问题的原因:http://www.cnblogs.com/nankezhishi/archive/2010/03/17/wpfbug13.html 解决方法:http://www.cnblogs.co ...
- img test
- General Palindromic Number (进制)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- pdf增加水印
/// <summary> /// 为PDF添加水印或背景图片 /// </summary> /// <param name="strSourceFilePat ...
- (转)Linux 文件系统:procfs, sysfs, debugfs 用法简介
网址:http://www.tinylab.org/show-the-usage-of-procfs-sysfs-debugfs/ 1 前言 内核中有三个常用的伪文件系统:procfs,debugfs ...
- springMVC+MyBatis+Spring 整合(3)
spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding=" ...
- linux 添加用户
1.下面就开始来说怎么添加新用户 我们以添加一个用户名为jorcen的新用户为例来说明,执行下面的命令: # useradd jorcen 2.那么就新用户就添加完成,但是没有任何信息,新用户添加完成 ...
- c++ 容器类
#include <iostream> #include <vector> #include <list> #include <map> using n ...