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 ...
随机推荐
- leetcode String相关
目录 3无重复字符的最长子串 5最长回文子串 8字符串转换整数(atoi), 9回文数,7整数反转 28实现strStr(), 459重复的子字符串(KMP) 43字符串相乘 71简化路径 93复原I ...
- Pet(dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=4707 题意:判断距离大于D的点有多少个. 思路: 邻接表建图,dfs每一个点,记录步数. #include &l ...
- 使用 Polyfill 而不再是 bable 来实践js新特性
现状 我们想要用ES6 语法来写 JavaScript.然而由于我们需要兼容老版本的浏览器,那些浏览器不支持 ES6,我们需要解决这个问题. 有一个标准的做法是:写 ES6 代码 → 将所有代码编译成 ...
- vmware 14黑屏处理办法
从12升级到了14,但是发现所有的虚拟机都不能用了,黑屏.挂起的时候反而会显示界面,但是继续运行就是黑屏. 记录下解决办法. 修复LSP 以管理员身份运行CMD命令: netsh winsock re ...
- BZOJ 4808 二分图最大独立集
思路: 棋盘是个二分图 那就把一个可以走的白点 向所有可以走的黑点连边 跑一个最大匹配 (匹配上了就代表这两个点不能共存) 最大独立集=sum-最大匹配 //By SiriusRen #incl ...
- T - Amusing Joke(map)
Problem description So, the New Year holidays are over. Santa Claus and his colleagues can take a re ...
- Y - Anton and Letters
Problem description Recently, Anton has found a set. The set consists of small English letters. Anto ...
- C - Lucky Numbers (easy)
Problem description Petya loves lucky numbers. Everybody knows that positive integers are lucky if t ...
- vs2008 启动IE浏览器 出现DW20.exe占用大量cpu 服务器iis 异常调试
DW20.exe占用大量cpu 服务器iis运行出现异常想查一下故障原因,发现有好几个DW20.exe进程,每个占用20%左右的cpu,在任务管理器中将其终止后,它又自动运行起来了 查了一下DW20. ...
- 5.13Mysql数据库Database
数据库的基本概念 1.什么是数据库: 用于存储和管理数据的仓库. 2.数据库的特点: 1.持久化存储数据的.其实数据库就是一个文件系统. 2.方便存储和管理数据 3.使用了统一的方式操作数据库---s ...