[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 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- uwsgi + nginx 部署python项目(一)
uWSGI uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uws ...
- Python-自定义函数-参数
一.自定义函数参数 1.种类 (1)位置参数 "x"就是位置参数 #!/usr/bin/env python # -*- coding: utf-8 -*- #author: di ...
- Mysql-问题解决记录
1.查看当前默认的配置文件位置 # mysqld --verbose --help | 'Default options' Default options are read from the foll ...
- Linux-Maven部署
一.Maven是什么 二.Maven部署 1.环境信息: (1)centos7.3 (2)jdk1.8 (3)maven3.5.3 2.安装jdk (1)下载地址[http://www.oracle. ...
- 第九周课程总结&实验报告七
实验任务详情: 完成火车站售票程序的模拟. 要求: (1)总票数1000张: (2)10个窗口同时开始卖票: (3)卖票过程延时1秒钟: (4)不能出现一票多卖或卖出负数号票的情况. package ...
- Java程序基本框架
对象:对象是类的一个实例,有状态和行为.例如,一条狗是一个对象,它的状态有:颜色.名字.品种:行为有:摇尾巴.叫.吃等. 类:类是一个模板,它描述一类对象的行为和状态.(Java是以类为组织单位) 方 ...
- CentOS下搭建docker+.net core
运行环境: CentOS 7.0 容器:Docker 1.13.1 .Net Core版本: .NET Core 2.1,安装详见 CentOS 7 下安装.NET Core SDK 2.1 1.安装 ...
- arm初识
一.CPU从指令集角度分类 1.1. CISC (X86) 1.1. 1. CISC CPU 指complex instruction set computer复杂指令集CPU 1.1.2. CIS ...
- vmware下使用nat方法联网
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Li_Zefeng/article/det ...
- nginx运行出现 file not found 错误处理原因
在阿里云装nginx+php+mysql nginx运行出现 file not found 错误处理原因 1,第一情况 location ~ \.php$ { # root html; fastcgi ...