4*4*4*4暴力+点的旋转+推断正方型

C. Captain Marmot
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.

Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.

Each mole i has a home placed at the position (ai, bi). Moving this mole one time means rotating his position point (xi, yi) 90 degrees counter-clockwise around it's home point (ai, bi).

A regiment is compact only if the position points of the 4 moles form a square with non-zero area.

Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.

The next 4n lines contain 4 integers xiyiaibi ( - 104 ≤ xi, yi, ai, bi ≤ 104).

Output

Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes).

Sample test(s)
input
4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0

output
1
-1
3
3

Note

In the first regiment we can move once the second or the third mole.

We can't make the second regiment compact.

In the third regiment, from the last 3 moles we can move once one and twice another one.

In the fourth regiment, we can move twice the first mole and once the third mole.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>using namespace std;const double pi=3.1415926/2.;
const int INF=0x3f3f3f3f;int n;
struct PT
{double x,y,hx,hy;
}pt[10][10];struct Point
{int x,y;
}A,B,C,D;int isSQRT(Point a,Point b,Point c,Point d)
{int i,j,sumt=0,sumo=0;double px[10],py[10];//代表6条边的 向量double 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 1;// 是正方形if(sumt==4)return 0;//是 矩形return 0;//都不是
}int main()
{scanf("%d",&n);while(n--){for(int i=0;i<4;i++){double a,b,c,d;scanf("%lf%lf%lf%lf",&a,&b,&c,&d);pt[i][0].x=a,pt[i][0].y=b;pt[i][0].hx=c,pt[i][0].hy=d;///....for(int j=1;j<4;j++){pt[i][j].x=pt[i][j-1].x;pt[i][j].y=pt[i][j-1].y;pt[i][j].hx=pt[i][j-1].hx;pt[i][j].hy=pt[i][j-1].hy;///x0= (x - rx0)*cos(a) - (y - ry0)*sin(a)  + rx0 ;///y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;pt[i][j].x=(pt[i][j-1].x-pt[i][j-1].hx)*0-(pt[i][j-1].y-pt[i][j-1].hy)*1+pt[i][j-1].hx;pt[i][j].y=(pt[i][j-1].x-pt[i][j-1].hx)*1+(pt[i][j-1].y-pt[i][j-1].hy)*0+pt[i][j-1].hy;}}int ans=INF;for(int i1=0;i1<4;i1++){for(int i2=0;i2<4;i2++){for(int i3=0;i3<4;i3++){for(int i4=0;i4<4;i4++){int temp=i1+i2+i3+i4;if(temp>ans) continue;A.x=pt[0][i1].x;A.y=pt[0][i1].y;B.x=pt[1][i2].x;B.y=pt[1][i2].y;C.x=pt[2][i3].x;C.y=pt[2][i3].y;D.x=pt[3][i4].x;D.y=pt[3][i4].y;if(isSQRT(A,B,C,D)==true)ans=min(ans,temp);}}}}if(ans==INF) ans=-1;printf("%d\n",ans);}return 0;
}

Codeforces 474 C. Captain Marmot相关推荐

  1. Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)

    题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...

  2. Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数

    题目链接:点击打开链接 题意: 给定T表示case数 以下4行是一个case 每行2个点,u v 每次u能够绕着v逆时针转90° 问最少操作多少次使得4个u构成一个正方形. 思路: 枚举判可行 #in ...

  3. Codeforces 474 D. Flowers

    简单递推.... D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standa ...

  4. CodeForces 474.D Flowers

    题意: 有n朵花排成一排,小明要么吃掉连续的k朵白花,或者可以吃单个的红花. 给出一个n的区间[a, b],输出总吃花的方法数模 109+7 的值. 分析: 设d(i)表示吃i朵花的方案数. 则有如下 ...

  5. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. 1 #include<bits/stdc++.h> 2 #de ...

  6. 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)

    终于打了一场CF,不知道为什么我会去打00:05的CF比赛-- 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...

  7. 【Codeforces】 2A - Winner (map)

    http://codeforces.com/problemset/problem/2/A So, if two or more players have the maximum number of p ...

  8. Codeforces上通过数超过5W人的题

    Codeforces上通过数超过5W人的题 共32题:1000分4题,800分28题. 编号 题号 题名 分数 通过数 1 4A Watermelon 800 x193501 2 71A Way To ...

  9. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

最新文章

  1. SSMSSH项目中 springmvc 乱码问题解决
  2. Linux 精准获取进程pid--转
  3. 2.3.3 进程互斥的硬件实现方法
  4. 我看西电通院月考——学生应该做点什么?
  5. 蓝桥杯单片机基础学习00_1
  6. [ExtJS5学习笔记]第三十五条 sencha extjs 5 组件查询方法
  7. php 替换 tab,PHP 删除字符串中的空格和换行符终极方法 - 文章教程
  8. 初学 Delphi 嵌入汇编[18] - SHL 与 SHR
  9. 30岁以上的女人应选择什么品牌的眼霜?
  10. 【数据结构与算法】内部排序之一:插入排序和希尔排序的N中实现(不断优化,附完整源码)...
  11. win10 计算机 桌面图标不见了,win10系统桌面图标没了的解决方法
  12. c语言屏蔽一段程序,C语言#if 0阻止代码段
  13. 高速EDA设计课程报告(三)
  14. word2vec中的数学原理详解
  15. 电脑网速,详细教您电脑网速慢怎么办
  16. echarts的用法
  17. 1111,你的能量够买包卫生巾吗?
  18. 怎么把计算机隐藏文件显示出来,怎么把隐藏的文件夹显示出来
  19. [bzoj3998]弦论
  20. LOESS局部加权非参数回归

热门文章

  1. Log4j日志使用记录
  2. ArcGIS JavaScript在线编辑
  3. PHPCMS_单入口初始化执行流程
  4. Virtual Machine Manager 2012 R2利用服务模板部署SQL
  5. Scientific Linux 6.4安装详程
  6. MyStringTokenize
  7. 东芝复印机2303出现f070_东芝复印机维修代码大全
  8. android sdk 文档导读之前传:初涉
  9. Sun 解决方案大会归来
  10. 80.简单搭建nodeJS服务,访问本地站点文件