F 点与多边形 数学 + 观察
https://biancheng.love/contest-ng/index.html#/123/problems
做题要在纸上弄弄,才会有发现。
发现到答案只是-1和4,因为坐标都是整数。
然后就是找是否存在正方形了。
判断如下:
1、枚举任意两个点,作为正方形的一条边,那么,整个正方形就确定了,有两个方向。
因为,
设坐标为(x1, y1) & (x2, y2),所求的坐标是和x1相连,那么有方程如下。
1、垂直,向量积是0
2、边长相等,然后距离公式化简。
即可解出剩下的两个点。
然后要注意两个点要在正方形的同一侧,不然变了平行四边形了。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
struct node {
int x, y;
bool operator < (const struct node & rhs) const {
if (x != rhs.x) {
return x < rhs.x;
} else return y < rhs.y;
}
bool operator != (const struct node & rhs) const {
return !(x == rhs.x && y == rhs.y);
}
} arr[];
int n;
bool check(struct node t1, struct node t2, int one, int two) {
int pos = lower_bound(arr + , arr + + n, t1) - arr;
if (pos == one || pos == two || arr[pos] != t1) return false;
pos = lower_bound(arr + , arr + + n, t2) - arr;
if (pos == one || pos == two || arr[pos] != t2) return false;
return true;
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d%d", &arr[i].x, &arr[i].y);
}
sort(arr + , arr + + n);
// for (int i = 1; i <= n; ++i) {
// cout << arr[i].x << " " << arr[i].y << endl;
// }
// cout << endl;
int ans = ;
for (int i = ; i <= n; ++i) {
for (int j = i + ; j <= n; ++j) {
struct node t[];
t[].x = arr[i].y - arr[j].y + arr[i].x;
t[].y = arr[j].x - arr[i].x + arr[i].y;
t[].x = arr[j].y - arr[i].y + arr[j].x;
t[].y = arr[i].x - arr[j].x + arr[j].y;
// cout << i << " " << j << endl;
// cout << "*********" << endl;
// for (int k = 0; k <= 1; ++k) {
// cout << t[k].x << " " << t[k].y << endl;
// }
// cout << "**********" << endl;
if (t[].x < arr[i].x || t[].x == arr[i].x && t[].y < arr[i].y) {
t[].x = arr[j].y - arr[i].y + arr[i].x;
t[].y = arr[i].x - arr[j].x + arr[i].y;
}
if (t[].x < arr[j].x || t[].x == arr[j].x && t[].y < arr[j].y) {
t[].x = arr[i].y - arr[j].y + arr[j].x;
t[].y = arr[j].x - arr[i].x + arr[j].y;
}
// for (int k = 0; k <= 1; ++k) {
// cout << t[k].x << " " << t[k].y << endl;
// }
if (check(t[], t[], i, j)) {
printf("4\n");
return;
} t[].x = arr[i].y - arr[j].y + arr[i].x;
t[].y = arr[j].x - arr[i].x + arr[i].y;
t[].x = arr[j].y - arr[i].y + arr[j].x;
t[].y = arr[i].x - arr[j].x + arr[j].y; if (t[].x > arr[i].x || t[].x == arr[i].x && t[].y > arr[i].y) {
t[].x = arr[j].y - arr[i].y + arr[i].x;
t[].y = arr[i].x - arr[j].x + arr[i].y;
}
if (t[].x > arr[j].x || t[].x == arr[j].x && t[].y > arr[j].y) {
t[].x = arr[i].y - arr[j].y + arr[j].x;
t[].y = arr[j].x - arr[i].x + arr[j].y;
}
// for (int k = 0; k <= 1; ++k) {
// cout << t[k].x << " " << t[k].y << endl;
// }
// cout << endl;
if (check(t[], t[], i, j)) {
printf("4\n");
return;
}
}
}
assert(ans >= );
printf("%d\n", -);
return;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
F 点与多边形 数学 + 观察的更多相关文章
- 牛客网多校第5场 F take 【思维+数学期望】
题目:戳这里 思路来源:视频讲解 题意:有n个箱子按1...n标号,每个箱子有大小为di的钻石概率为pi,我们初始有个大小为0的钻石,从1到n按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期 ...
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
- F. Multicolored Markers(数学思维)
思维:思维就是将大的矩形放在小矩形里面,让大矩形的宽和长尽量靠近. 很容易得到 (a+b)% i = 0 的话, 保证了大矩形的形成,同时里面表示了两种情况:1, a % i =0, b % i=0; ...
- 快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0
实在太冷了今天 taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了 2 语句顺序错 double cola: 忘了减去n的序号1,即n-- B. Taxi ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- Codeforces Round #697 (Div. 3) F. Unusual Matrix (思维,数学)
题意:给你一个矩阵\(a\)和\(b\),你可以对\(a\)的任意一行或任意一列的所有元素xor\(1\)任意次,问最终是否能够得到\(b\). 题解:由\(a\ xor\ b=c\),可得:\(a\ ...
- cf Round 603
A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
- 【专题】计数问题(排列组合,容斥原理,Prufer序列)
[容斥原理] 对于统计指定排列方案数的问题,一个方案是空间中的一个元素. 定义集合x是满足排列中第x个数的限定条件的方案集合,设排列长度为S,则一共S个集合. 容斥原理的本质是考虑[集合交 或 集合交 ...
- 2014 39th ACM-ICPC 西安赛区 总结
西安,打铁. 出发前听说是大赛区,签到的时候看了秩序册的队伍情况,264支队伍. 在听说是大赛区之前,我觉得我们队应该是银首,运气好+发挥超常的话或许有金,即保银冲金. 听到大赛区之后,觉得可能金区有 ...
随机推荐
- 非计算机专业的伟伯是怎样拿到阿里Offer的。求职励志!!!
写在前面: 2015 年 7 月初.參加阿里巴巴校招内推, 8 月 15 日拿到研发project师 JAVA 的 offer .我的专业并不是计算机,也没有在互联网公司实习过,仅仅有一些学习和面试心 ...
- 重载和重写在jvm运行中的区别(一)
1.重载(overload)方法 对重载方法的调用主要看静态类型,静态类型是什么类型,就调用什么类型的参数方法. 2.重写(override)方法 对重写方法的调用主要看实际类型.实际类型如果实现了该 ...
- 初识mina框架
step1:创建java工程,导入jar包 step2:在src下配置log4j.properties文件 log4j.rootLogger=DEBUG,MINA,file log4j.appende ...
- python 【第二篇】python基本数据类型
python数据类型 python的数据类型和大多数编程语言一样,有int,float,long,string但是python有三个特殊的数据类型:列表,元组,字典 如果不知道你的数据类型有什么方法: ...
- 图像处理之基础---opencv 开发的环境搭建
vs2010 opencv2.4.8 下载: vs2010 http://opencv.org/ 步骤: http://my.phirobot.com/blog/2014-02-opencv_conf ...
- mysql字段去重方式
一直找不出某个字段去重的前提下,还能够显示其它字段的数据 以下是解决方法: SELECT *, COUNT(DISTINCT( province)) FROM area_info WHERE type ...
- vim插件:显示树形目录插件NERDTree安装 和 使用【转】
本文转载自:https://my.oschina.net/VASKS/blog/388907 下载和配置 NERDTree插件的官方地址如下,可以从这里获取最新的版本 https://github.c ...
- Dancing Links 专题总结
算法详细:Dancing Links博客 1.精确覆盖: ZOJ3209 Treasure Map HUST1017 Exact cover POJ3074 Sudoku 2.可重复覆盖: HDU22 ...
- HDU3001 Travelling —— 状压DP(三进制)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3001 Travelling Time Limit: 6000/3000 MS (Java/ ...
- 03_隐式意图打开activity
想让第一个activity把第二个activity打开的话,在清单文件里面声明一下并且 右键Debug As Android Application居然没有报错 mimeType 讲HTML的时候就 ...