[517]Kite 题解
前言
今天又是爆零的一天。
被同学坑了,还以为四边形的点是按任意序给定的,然后打了一个特别复杂的矩形判断QAQ。
题意简述
按顺序给定一个四边形,求有多少个点在这个四边形的对称轴上。
题解
分情况讨论:
正方形有8个点。
菱形和矩形有4个点。
筝形和等腰梯形有2个点。
剩余的有0个点。
代码
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
namespace fast_IO{
const int IN_LEN = 10000000, OUT_LEN = 10000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf, *lastin = ibuf + IN_LEN, *lastout = obuf + OUT_LEN - 1;
inline char getchar_(){return (ih == lastin) && (lastin = (ih = ibuf) + fread(ibuf, 1, IN_LEN, stdin), ih == lastin) ? EOF : *ih++;}
inline void putchar_(const char x){if(oh == lastout) fwrite(obuf, 1, oh - obuf, stdout), oh = obuf; *oh ++= x;}
inline void flush(){fwrite(obuf, 1, oh - obuf, stdout);}
int read(){
int x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar_();
if (ch == '-') zf = -1, ch = getchar_();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar_(); return x * zf;
}
void write(int x){
if (x < 0) putchar_('-'), x = -x;
if (x > 9) write(x / 10);
putchar_(x % 10 + '0');
}
}
using namespace fast_IO;
#define x first
#define y second
#define Pos pair<double, double>
Pos pos[4];
const double EPS = 1e-8;
inline bool eql(double a, double b){
return (abs(a - b) <= EPS);
}
inline double getDis(Pos a, Pos b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool ggdl(int pos1, int pos2, int pos3){
double dis1 = getDis(pos[pos1], pos[pos2]);
double dis2 = getDis(pos[pos2], pos[pos3]);
double dis3 = getDis(pos[pos1], pos[pos3]);
return (eql(dis1 + dis2, dis3) || eql(dis1 + dis3, dis2) || eql(dis2 + dis3, dis1));
}
bool isJx(){
double x_c = (pos[0].x + pos[1].x + pos[2].x + pos[3].x) / 4.0;
double y_c = (pos[0].y + pos[1].y + pos[2].y + pos[3].y) / 4.0;
double d1 = getDis(pos[0], make_pair(x_c, y_c));
double d2 = getDis(pos[1], make_pair(x_c, y_c));
double d3 = getDis(pos[2], make_pair(x_c, y_c));
double d4 = getDis(pos[3], make_pair(x_c, y_c));
return (d1 == d2 && d1 == d3 && d1 == d4);
}
bool isLx(){
double s12 = getDis(pos[0], pos[1]);
double s14 = getDis(pos[0], pos[3]);
double s23 = getDis(pos[1], pos[2]);
double s34 = getDis(pos[2], pos[3]);
return (s12 == s14 && s14 == s23 && s23 == s34);
}
bool isZs(){
bool zs1 = eql(getDis(pos[0], pos[1]), getDis(pos[1], pos[2])) && eql(getDis(pos[0], pos[3]), getDis(pos[3], pos[2]));
bool zs2 = eql(getDis(pos[0], pos[1]), getDis(pos[0], pos[3])) && eql(getDis(pos[2], pos[1]), getDis(pos[2], pos[3]));
return (zs1 || zs2);
}
bool tx(){
bool x = eql(getDis(pos[0], pos[1]), getDis(pos[2], pos[3]));
x = x || (eql(getDis(pos[1], pos[2]), getDis(pos[0], pos[3])));
return (eql(getDis(pos[0], pos[2]), getDis(pos[1], pos[3])) && x);
}
int main(){
for (int i = 0; i < 4; ++i) pos[i].x = read(), pos[i].y = read();
bool jx = isJx(), lx = isLx();
if (jx && lx)
puts("8");
else if (jx || lx)
puts("4");
else{
if (isZs() || tx())
puts("2");
else
puts("0");
}
return 0;
}
[517]Kite 题解的更多相关文章
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...
- URAL 1963 Kite 计算几何
Kite 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/C Description Vova bought a kite con ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
- 题解【洛谷P2615】[NOIP2015]神奇的幻方
题目描述 幻方是一种很神奇的 \(N \times N\) 矩阵:它由数字 \(1,2,3,\cdots \cdots ,N \times N\) 构成,且每行.每列及两条对角线上的数字之和都相同. ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- 【HANA系列】SAP HANA SQL获取当前月的第一天
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取当前 ...
- 《深入浅出WPF》学习总结之控件与布局
一.控件到底是什么 控件的本质是“数据+算法”——用户输入原始数据,算法处理原始数据并得到结果数据.问题就在于程序如何将结果数据展示给用户.同样一组数据,你可以使用LED阵列显示出来,或者是以命令行模 ...
- python 并发编程 多进程 互斥锁与join区别
互斥锁与join 互斥锁和join都可以把并发变成串行 以下代码是用join实现串行 from multiprocessing import Process import time import js ...
- python并发编程之进程池、线程池、协程
需要注意一下不能无限的开进程,不能无限的开线程最常用的就是开进程池,开线程池.其中回调函数非常重要回调函数其实可以作为一种编程思想,谁好了谁就去掉 只要你用并发,就会有锁的问题,但是你不能一直去自己加 ...
- 实用网站推荐——office模板(PPT)
今天给大家分享一批Office的模板网站! office模板比较多的是PPT模板,做PPT是一件非常痛苦的事,自己做的要么太丑,要么搭配太单一,所以今天给大家分享一批网站,再也不用愁做PPT了. wo ...
- [转帖]100G QSFP28与CFP,CFP2,CFP4光模块的比较
100G QSFP28与CFP,CFP2,CFP4光模块的比较 https://www.eefocus.com/etulink/blog/17-09/423967_5c520.html 数据中心网络发 ...
- debian 安装java
sudo apt-get update sudo apt-get install default-jre sudo apt-get install default-jdk
- adb常用命令和抓取log的方法
一 adb常用的几个命令1. 查看设备adb devices这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示 C:\Documents and Settings\ ...
- Linux0.11之初识Makefile/build.c
前言 Makefile对于从来没有接触过的人来说是相当别扭的(比如我),但它确实又是非常重要的,它描述了一个Image是如何形成的,理解它也许并不能帮我解决实际问题,而且编写Makefile的工作也许 ...
- java代码转化为jar包,再转化为.exe文件步骤
下面是具体步骤: 一.先把自己的程序发布成jar文件 这是eclipse自带的功能,右键工程包-->Export 然后选择Java-->JAR file,next 选择输出路径,next ...