Description

Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.

Input

You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no tw

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
int p[]={0,1,2,3,4,5,6,7,8};
int x[9],y[9];
int d(int a,int b)
{
return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
}
int main()
{
int i,j;
for(i=1;i<=8;i++)scanf("%d%d",&x[i],&y[i]); do
{
if(d(p[1],p[2])==d(p[2],p[3]) && d(p[2],p[3])==d(p[3],p[4]) && d(p[3],p[4])==d(p[4],p[1]) && d(p[1],p[3])==d(p[4],p[2])
&& d(p[5],p[6])==d(p[7],p[8]) && d(p[5],p[8])==d(p[6],p[7]) && d(p[5],p[7])==d(p[6],p[8]))
{
return printf("YES\n%d %d %d %d\n%d %d %d %d\n",p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),0;
}
}while(next_permutation(p+1,p+9));
printf("NO\n");
return 0; }

  

o points coincide.

Output

Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.

If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.

Sample Input

Input
0 0
10 11
10 0
0 11
1 1
2 2
2 1
1 2
Output
YES
5 6 7 8
1 2 3 4
Input
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
Output
NO
Input
0 0
4 4
4 0
0 4
1 2
2 3
3 2
2 1
Output
YES
1 2 3 4
5 6 7 8
一开始不想敲,认为就是个全排列,没什么,网上搜了一下解题报告,确实是用全排列把所有的情况找出来,但是别人用了一个我认为非常吊的方法,调用stl里的全排列函数,屌爆了。
膜拜一下,STL里还有什么宝贝赶紧去找找。

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. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

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

  3. Rectangle and Square(判断正方形、矩形)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...

  4. Matlab 进阶学习记录

    最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录: 1. conf_proposal  =  proposal_config('image_means', ...

  5. POJ 3449 Geometric Shapes --计算几何,线段相交

    题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...

  6. RTTI (Run-Time Type Identification,通过运行时类型识别) 转

    参考一: RTTI(Run-Time Type Identification,通过运行时类型识别)程序能够使用基类的指针或引用来检查这些指针或引用所指的对象的实际派生类型.   RTTI提供了以下两个 ...

  7. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习

    # Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...

  8. cdoj 93 King's Sanctuary 傻逼几何题

    King's Sanctuary Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/sho ...

  9. C++中str1::function和bind

    在C++的TR1中(TechnologyReport)中包括一个function模板类和bind模板函数,使用它们能够实现类似函数指针的功能,但却却比函数指针更加灵活,特别是函数指向类的非静态成员函数 ...

随机推荐

  1. DataTables选择行并删除(删除单行)

    $(document).ready(function() { var table = $('#example').DataTable(); $('#example tbody').on( 'click ...

  2. 现有C2B模式小总结

    现有的C2B模式 目前常见的C2B模式有: l  聚合需求形式(反向团购.预售等) l  要约形式(逆向拍卖,客户出价,商家选择是否接受等) l  服务认领形式(企业发布所需服务,个人认领,类似威客等 ...

  3. oracle的resetlogs机制浅析

    oracle的resetlogs机制浅析 alter database open resetlogs 这个命令我想大家都很熟悉了,那有没有想过这个resetlogs选项为什么要用?什么时候用?它的原理 ...

  4. mysql 导出导入sql

    >mysqldump -u用户名 -p密码 -h主机名 数据库名 > 20150116mw_pm_db.sql mysql> source /home/y/my_work/20150 ...

  5. 设置ActioinBar 的背景色以及Title的字体颜色

    //设置ActionBar背景 Drawable draw=this.getResources().getDrawable(R.drawable.actionbar_bg); getActionBar ...

  6. POJ 2152 Fire(树形DP)

    题意: 思路:令F[i][j]表示 的最小费用.Best[i]表示以i为根节点的子树多有节点都找到负责消防站的最小费用. 好难的题... #include<algorithm> #incl ...

  7. Doxygen安装使用

    Doxygen是一个 C++.C.Java.Objective-C.Python.IDL(CORBA和Microsoft flavors).Fortran.VHDL.PHP.C#和D语言的文檔生成器. ...

  8. 多系统实现单点登录方案:SSO 单点登录

    一.什么是单点登录SSO(Single Sign-On) SSO是一种统一认证和授权机制,指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用 ...

  9. Longest Common Prefix 解答

    Question Write a function to find the longest common prefix string amongst an array of strings. Solu ...

  10. 第02讲- Android开发环境

    第02讲Android开发环境 需要下载的软件: JDK(JavaDevelopment Kit) Eclipse AndroidSDK(SoftwareDevelopmentKit) ADT(And ...