题意:给定 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. MapReduce启动的Map/Reduce子任务简要分析

      对于Hadoop来说,是通过在DataNode中启动Map/Reduce java进程的方式来实现分布式计算处理的,那么就从源码层简要分析一下hadoop中启动Map/Reduce任务的过程.   ...

  2. 第一章 安装ubuntu

    最近正在研究hadoop,hbase,准备自己写一套研究的感研,下面先讲下安装ubuntu,我这个是在虚拟机下安装,先用 文件转换的方式安装. 1:选择语言:最好选择英文,以免出错的时候乱码 2:选择 ...

  3. Oracle归档与非归档模式

    一.什么是Oracle归档模式 Oracle数据库有联机重做日志,这个日志是记录对数据库所做的修改,比如插入,删除,更新数据等,对这些操作都会记录在联机重做日志里.一般数据库至少要有2个联机重做日志组 ...

  4. 爬虫高性能相关(协程效率最高,IO密集型)

    一背景常识 爬虫的本质就是一个socket客户端与服务端的通信过程,如果我们有多个url待爬取,采用串行的方式执行,只能等待爬取一个结束后才能继续下一个,效率会非常低. 需要强调的是:串行并不意味着低 ...

  5. ALSA声卡笔记2---ASoC驱动框架

    1.简单了解一下ASOC 在嵌入式系统里面的声卡驱动为ASOC(ALSA System on Chip) ,它是在ALSA 驱动程序上封装的一层   分为3大部分,Machine,Platform和C ...

  6. 5月3日上课笔记-properties文件,junit测试,mvc封层等

    StringBuffer 线程安全,效率低 StringBuilder 线程不安全,效率高 判断数组是null还是空数组 null 空数组 int[] array=null; int[] array2 ...

  7. SSH框架的简化(struts2、spring4、hibernate5)

    目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.本文提纲:本文通过一个新闻管理系统的实例来简化ssh框架的代码编写,功能包括查询数据库中 ...

  8. file_get_content服务器对服务器二进制文件上传

    1.file_get_contents函数可安全用于二进制对象,适用服务器对服务器文件是上传场景 base64_encode(file_get_contents('1268879774AaCl4wIE ...

  9. Tkinter Radiobutton

    Python GUI - Tkinter Radiobutton: 这个小部件实现了多项选择按钮,这是一种方式向用户提供许多可能的选择,让用户选择只是其中之一.   这个小部件实现了多项选择按钮,这是 ...

  10. C# 本地文件夹上传至网络服务器中(待续)

    一.文件的上传参考 思想,C#FTP上传 /// <summary> /// 上传 /// </summary> /// <param name="filena ...