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. OC常用的数学函数及宏定义

    一.函数 1. 三角函数 double sin (double);正弦 double cos (double);余弦 double tan (double);正切 2 .反三角函数 double as ...

  2. 洛谷P2916 [USACO08NOV]为母牛欢呼(最小生成树)

    P2916 [USACO08NOV]为母牛欢呼Cheering up the C… 题目描述 Farmer John has grown so lazy that he no longer wants ...

  3. 使用idea2.5建立maven项目

    使用idea的步骤: 1.建立一个新的maven项目 2.选中maven项目 3.点击next,输入groupID和artifactid 4.点击next  选择projectlocation 5.选 ...

  4. BZOJ 3727 DP?推式子..

    思路: 设$sum[i]表示i的子树中a[i]的和$ $b[1]=\Sigma a[i]*dis[i] = \Sigma _{i=2} ^n sum[i]$ $b[x]-b[fa[x]]=sum[1] ...

  5. Vue跨域访问,axios&cors

    先安装node.js和npm,这个不用说了,直接在创建vue项目,然后实践一下跨域访问. 如果npm安装较慢,可安装淘宝镜像,执行下面命令: npm install -g cnpm --registr ...

  6. vue-router简单用法

    路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮  => home 内容, ...

  7. T-SQL查询高级--理解SQL SERVER中非聚集索引的覆盖,连接,交叉和过滤

      写在前面:这是第一篇T-SQL查询高级系列文章.但是T-SQL查询进阶系列还远远没有写完.这个主题放到高级我想是因为这个主题需要一些进阶的知识作为基础..如果文章中有错误的地方请不吝指正.本篇文章 ...

  8. Linux下Shell脚本输出带颜色文字

    文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置作用如下: 背景色为蓝色 ...

  9. [iOS Reverse]logify日志追踪,锁定注入口-控制台查看

    前言 logify是theos的一个组件,路径是: /opt/theos/bin/logify.pl 我们还是以微信红包为例子,根据[iOS Hacking]运行时分析cycript得到的入口文件: ...

  10. hexo搭建博客

    在使用hexo搭建个人博客的时候,修改.yml文件后出现错误:FATAL can not read a block mapping entry; a multiline key may not be ...