Codeforces 474 C. Captain Marmot
4*4*4*4暴力+点的旋转+推断正方型
1 second
256 megabytes
standard input
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.
The first line contains one integer n (1 ≤ n ≤ 100),
the number of regiments.
The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).
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).
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
1
-1
3
3
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的更多相关文章
- 【CODEFORCES】 C. Captain Marmot
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- C. Captain Marmot (Codeforces Round #271)
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 271 Div 2 C. Captain Marmot
题目链接:http://codeforces.com/contest/474/problem/C 解题报告:给一个n,然后输入4*n个平面坐标系上的点,每四个点是一组,每个点有一个中心,这四个点可以分 ...
- Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数
题目链接:点击打开链接 题意: 给定T表示case数 以下4行是一个case 每行2个点,u v 每次u能够绕着v逆时针转90° 问最少操作多少次使得4个u构成一个正方形. 思路: 枚举判可行 #in ...
- CodeForces 474C Captain Marmot (数学,旋转,暴力)
题意:给定 4n * 2 个坐标,分成 n组,让你判断,点绕点的最少次数使得四个点是一个正方形的顶点. 析:那么就一个一个的判断,n 很小,不会超时,四个点分别从不转然后转一次,转两次...转四次,就 ...
- Codeforces 474 E. Pillars
水太...... E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 474.D Flowers
题意: 有n朵花排成一排,小明要么吃掉连续的k朵白花,或者可以吃单个的红花. 给出一个n的区间[a, b],输出总吃花的方法数模 109+7 的值. 分析: 设d(i)表示吃i朵花的方案数. 则有如下 ...
- Codeforces 474 F. Ant colony
线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
随机推荐
- AAC帧格式及编码介绍
参考资料: AAC以adts格式封装的分析:http://wenku.baidu.com/view/45c755fd910ef12d2af9e74c.html aac编码介绍:http://wenku ...
- C#(服务器)与Java(客户端)通过Socket传递对象(序列化 json)
下面详细讲解实现的关键步骤: 通信关键: C#和java用Socket通信,发送数据和接收数据可以统一采用UTF-8编码,经过测试,使用UTF-8编码可以成功传递对象. 对于Sock ...
- 什么是 less? 如何使用 less?
什么是 Less? Less 是一门 CSS 预处理语言,它扩充了 CSS 语言,增加了诸如变量.混合(mixin).嵌套.函数等功能,让 CSS 更易编写.维护等. 本质上,Less 包含一套自定义 ...
- C#利用ICSharpCode将远程文件打包并下载
应用于ASP.NET MVC中 方法主体代码: public void GetFilesByOrder(string Order_ID, string IntNumber) { MemoryStrea ...
- Shiro图解
- IIS 7.0、IIS 7.5 和 IIS 8.0 使用的 HTTP 状态代码【转载自微软官方】
HTTP 状态代码 本部分描述 IIS 7.0.IIS 7.5 和 IIS 8.0 使用的 HTTP 状态代码. 注意 本文不会列出 HTTP 规范中所述的每个可能的 HTTP 状态代码.本文只包括 ...
- ie8及其以下版本兼容性问题之文本省略
1. 单行文本省略 单行文本省略适用于文本超出内容显示区,则在末尾显示省略号 1.1 普通文本超出省略 普通文本超出显示省略号,示例: .p{ height: 30px line-height: 30 ...
- 读书笔记「Python编程:从入门到实践」_11.测试函数
11.1 测试函数 要学习测试,得有要测试的代码.下面是一个简单的函数,它接受名和姓并返回整洁的姓名: def get_formatted_name(first, last): "" ...
- php多进程防止出现僵尸进程
对于用PHP进行多进程并发编程,不可避免要遇到僵尸进程的问题. 僵尸进程是指的父进程已经退出,而该进程dead之后没有进程接受,就成为僵尸进程(zombie)进程.任何进程在退出前(使用exit退出) ...
- C#使用OracleDataReader返回DataTable
string data = string.Empty; DataTable OutDataTable = new DataTable(); OracleDataReader daReader = cm ...