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】 C. Captain Marmot

    C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. C. Captain Marmot (Codeforces Round #271)

    C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces 271 Div 2 C. Captain Marmot

    题目链接:http://codeforces.com/contest/474/problem/C 解题报告:给一个n,然后输入4*n个平面坐标系上的点,每四个点是一组,每个点有一个中心,这四个点可以分 ...

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

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

  5. CodeForces 474C Captain Marmot (数学,旋转,暴力)

    题意:给定 4n * 2 个坐标,分成 n组,让你判断,点绕点的最少次数使得四个点是一个正方形的顶点. 析:那么就一个一个的判断,n 很小,不会超时,四个点分别从不转然后转一次,转两次...转四次,就 ...

  6. Codeforces 474 E. Pillars

    水太...... E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. CodeForces 474.D Flowers

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

  8. Codeforces 474 F. Ant colony

    线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...

  9. Codeforces Round #271 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...

随机推荐

  1. bzoj 3598 [ Scoi 2014 ] 方伯伯的商场之旅 ——数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3598 数位DP...东看西看:http://www.cnblogs.com/Artanis/ ...

  2. C/C++中的位运算符

    --------开始-------- 我自己都记不住这是第几次把这几个位运算符搞混了,刚好在刚用过来把这几个位运算符记下来,俗话说的好好记性不如个烂笔头. 运算符: 与           或    ...

  3. 【LOJ#10115,tyvj1473】校门外的树(第3次升级)

    PS:思路来源于Clove_unique的博客,在此万分感谢 这道题可以用树状数组轻松过,然而...树状数组不太熟悉,还是用线段树比较好(虽然代码比较长) [思路分析] [一开始的思路] 最开始的错误 ...

  4. B - Bit++

    Problem description The classic programming language of Bitland is Bit++. This language is so peculi ...

  5. 使用cnblogs发布第一篇文章,HelloWorld

    HelloWorld! 瞅瞅源码的样式,嗯,语法高亮还是可以的,辨识度还是挺高的. <!DOCTYPE html> <html> <head> <meta c ...

  6. SharedPreferences用法

    SharedPreferences是Android四种数据存储技术中的一种,它是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信 息,其对 ...

  7. 安卓代码迁移:ActionBarActivity: cannot be resolved to a type

    参考链接:http://stackoverflow.com/questions/18830736/actionbaractivity-cannot-be-resolved-to-a-type in e ...

  8. (转)Arcgis for Js之GeometryService实现测量距离和面积

    http://blog.csdn.net/gisshixisheng/article/details/40540601 距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryServ ...

  9. Python-通过configparser读写配置文件

    Python读写配置文件: 1.创建配置文件(文件名以.conf或.ini结束的文件表示配置文件) 2.导入所需模块 OS, configparser >>> import os & ...

  10. 浅谈Json数据格式

    我们先来看下w3cschool对json的定义: JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON 是存储和交换文本信息的语法.类似 XM ...