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 ...
随机推荐
- runC爆严重安全漏洞,主机可被攻击!使用容器的快打补丁
runC 是 Docker,Kubernetes 等依赖容器的应用程序的底层容器运行时.此次爆出的严重安全漏洞可使攻击者以 root 身份在主机上执行任何命令. 容器的安全性一直是容器技术的一个短板. ...
- nodejs windows环境安装
相信对于很多关注javascript发展的同学来说,nodejs已经不是一个陌生的词眼.有关nodejs的相关资料网上已经铺天盖地.由于它的高并发特性,造就了其特殊的应用地位. 国内目前关注最高,维护 ...
- Python 36 GIL全局解释器锁 、vs自定义互斥锁
一:GIL全局解释器锁介绍 在CPython中,全局解释器锁(或GIL)是一个互斥锁, 它阻止多个本机线程同时执行Python字节码.译文:之所以需要这个锁, 主要是因为CPython的内存管理不是线 ...
- Nginx代理配置-centos6.10版
nginx代理配置 cd /etc/nginx/init.d vi default.conf 添加: upstream server1{ server 192.168.125.128:8100 wei ...
- BZOJ 1407 exgcd
思路: 数据范围不大.. 那我们就枚举M好了.. 再两两判断一下有没有冲突 怎么判断呢? exgcd!!! p[i]*k+c[i]=p[j]*k+c[j] (mod m) (p[j]-p[i])*k ...
- CDH版Phoenix的安装(图文详解)
不多说,直接上干货! 写在前面的话 我这里,四个节点的bigdata集群.分别为cmbigdata1.cmbigdata2.cmbigdata3和cmbigdata4. https://i.cnblo ...
- Spring Boot (1) 构建第一个Spring Boot工程
Spring boot简介 spring boot是spring官方推出的一个全新框架,其设计目的是用来简化新spring应用的初始搭建以及开发过程. Spring boot特点 1.化繁为简,简化配 ...
- SQLServer2008 关于Group by
如果我们想知道每个国家有多少种水果,那么我们可以通过如下SQL语句来完成: SELECT COUNT(*) FruitName AS 水果种类, ProductPlace AS 出产国 FROM T_ ...
- Linux的那点事
1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...
- Glitch-free clock switch
With multi-frequency clocks being used in today’s devices, it's necessary to switch the source of a ...