题意:给定 4n * 2 个坐标,分成 n组,让你判断,点绕点的最少次数使得四个点是一个正方形的顶点。

析:那么就一个一个的判断,n 很小,不会超时,四个点分别从不转然后转一次,转两次。。。转四次,就这样算下去,那么如何判断是不是正方形呢?这样判定就行,把每个边都求出来,然后判定,

这里肯定有四个边是一样,另外两个是一样的,而且还不是0,因为可能重合,关键是旋转后怎么算呢?有两个公式,假设点(x, y)绕点(a, b)转 x 角度,那么旋转后的坐标为 (xx, yy),应该是,

xx = (x - a) cos x - (y-b) sin x + a; yy = (x-a) sin x + (y-b) cos x + b;这就是转任意角度的结果。那么剩下的就很简单了,注意,如果用int 可能会溢出,用double注意精度。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 400 + 5;
int a[maxn], b[maxn], x[maxn], y[maxn];
int xx[5], yy[5]; void rot(int t, int *s){//旋转
for(int i = 0; i < 4; ++i){//四个点旋转
xx[t+i] = x[t+i], yy[t+i] = y[t+i];
for(int j = 0; j < s[i]; ++j){//第 i 个数旋转
int xxx = xx[t+i];
xx[t+i] = a[t+i] - yy[t+i] + b[t+i];
yy[t+i] = xxx - a[t+i] + b[t+i];
}
}
} bool judge(int t, int *x, int *y){
vector<LL> v;
for(int i = 0; i < 4; ++i)
for(int j = 0 ; j < 4; ++j){
if(i == j) continue;
LL xx = ((LL)x[t+i]-(LL)x[t+j]) * ((LL)x[t+i]-(LL)x[t+j]) + ((LL)y[t+i]-(LL)y[t+j]) * ((LL)y[t+i]-(LL)y[t+j]);//计算边长
v.push_back(xx);//记录边长
} sort(v.begin(), v.end());//排序 int tt = 0, ii = 0;//计算数量
for(int i = 0 ; i < 12; ++i){
if(v[i] == v[0] && v[i]) ++tt;
else if(v[i] == v[11] && v[i]) ++ii;
}
if(tt == 8 && ii == 4) return true;
return false;
} int solve(int t){
int ans = 1000;
for(int i = 0; i < 4; ++i)
for(int j = 0; j < 4; ++j)
for(int k = 0; k < 4; ++k)
for(int l = 0; l < 4; ++l){
if(ans < i + j + k +l) continue;//如果小于才循环
int s[] = {i, j, k, l};
rot(t, s);
if(judge(t, xx, yy)) ans = i + j + k + l;
} return ans == 1000 ? -1 : ans;
} int main(){
int n;
cin >> n;
for(int i = 1; i <= 4*n; ++i) scanf("%d %d %d %d", &x[i], &y[i], &a[i], &b[i]); for(int i = 1; i < 4*n; i += 4)
cout << solve(i) << endl; return 0;
}

CodeForces 474C Captain Marmot (数学,旋转,暴力)的更多相关文章

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

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

  2. Codeforces 474 C. Captain Marmot

    4*4*4*4暴力+点的旋转+推断正方型 C. Captain Marmot time limit per test 1 second memory limit per test 256 megaby ...

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

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

  4. 【CODEFORCES】 C. Captain Marmot

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

  5. Codeforces 271 Div 2 C. Captain Marmot

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

  6. codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)

    题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...

  7. Codeforces Gym 100513M M. Variable Shadowing 暴力

    M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...

  8. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  9. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

随机推荐

  1. View.findViewById()和Activity.findViewById()区别

    在网上看见View.findViewById() 和 Activity.findViewById()执行效率不一样 使用Activity.findViewById()如: TextView tv_in ...

  2. sqlldr加载 数据文件的字段超出最大长度

    SQLLOAD数据的时候,建表给的字段给够了,建表已经给到VHARCHAR2(1024)了,实际数据是VHARCHAR2(256).加载报错"数据文件的字段超出最大长度"查了半天, ...

  3. linux加程序是否当掉检测脚本

    cd $(dirname $) source ~/.bash_profile SYSTEM_TIME=`date '+%Y-%m-%d %T'` count=`ps -ef |grep "p ...

  4. Idea2016远程调试Java项目

    一.在IDEA中配置远程tomcat 1.打开配置页面 选择"+" → "Tomcat Server" → "Remote" 填写名称和目标 ...

  5. yum问题的解决办法

     关于使用yum“The program package-cleanup is...”的解决办法   在使用yum 时总是有提示信息: The program package-cleanup is f ...

  6. 10_java之继承和抽象类

    01继承的概述 *A:继承的概念 *a:继承描述的是事物之间的所属关系,通过继承可以使多种事物之间形成一种关系体系 *b:在Java中,类的继承是指在一个现有类的基础上去构建一个新的类, 构建出来的新 ...

  7. array,vector对象 数组越界检测

  8. [z]单次遍历带权随机选取

    http://www.gocalf.com/blog/weighted-random-selection.html 没事可以看看,这个博客里面很多文章不错

  9. 如何清除svn的账号缓存信息(solaris)

    如果我们不小心输入svn账号错误的话,后面就一直提示认证失败,不能checkout代码. 这个是因为svn把你输入的账号进行了缓存. 如果我们想重新输入新的账号,必须要清除缓存 svn存储账号的目录在 ...

  10. Rhythmk 一步一步学 JAVA (18) Axis2 创建 WebService

    一 > 环境配置 1.下载Axis2: 目前版本为 1.6.2 下载地址: http://axis.apache.org/axis2/java/core/ 下载 axis2-1.6.2-bin. ...