前言

今天又是爆零的一天。

被同学坑了,还以为四边形的点是按任意序给定的,然后打了一个特别复杂的矩形判断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 题解的更多相关文章

  1. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】

    A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...

  2. URAL 1963 Kite 计算几何

    Kite 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/C Description Vova bought a kite con ...

  3. LeetCode All in One题解汇总(持续更新中...)

    突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...

  4. 题解【洛谷P2615】[NOIP2015]神奇的幻方

    题目描述 幻方是一种很神奇的 \(N \times N\) 矩阵:它由数字 \(1,2,3,\cdots \cdots ,N \times N\) 构成,且每行.每列及两条对角线上的数字之和都相同. ...

  5. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  6. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  7. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  8. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  9. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

随机推荐

  1. python接口自动化:requests+ddt+htmltestrunner数据驱动框架

    该框架分为四个包:xc_datas.xc_driven.xc_report.xc_tools. xc_datas:存放数据,xc_driven:存放执行程序,xc_report:存放生成的报告,xc_ ...

  2. 【Linux开发】Ubuntu图形界面切换与磁盘扩展分区

    Ubuntu14.04设置字符界面快捷键:ctrl-alt-f1 切换回图形界面:ctrl-alt-f7 为虚拟机拓展了30G的空间,挂在了/mnt/sda3这个目录下: 说明一下Ubuntu14.0 ...

  3. linux 运行时加载不上动态库 解决方法(转)

    1. 连接和运行时库文件搜索路径到设置     库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr ...

  4. Java内存管理和回收

    转载自http://blog.csdn.net/cutesource/article/details/5906705 JVM内存组成结构 JVM栈由堆.栈.本地方法栈.方法区等部分组成,结构图如下所示 ...

  5. 使用logstash收集java、nginx、系统等常见日志

    目录 1.使用codec的multiline插件收集java日志... 1 2.收集nginx日志... 2 3.收集系统syslog日志... 3 4.使用fliter的grok模块收集mysql日 ...

  6. vue插槽用法(极客时间Vue视频笔记)

    vue插槽 插槽是用来传递复杂的内容,类似方法 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  7. java8-----lambda语法

    // -----lambda语法1------ https://www.baidu.com/link?url=6iszXQlsmyaoWVZMaPs3g8vLRQXzdzTnKzQYTF8lg-5QQ ...

  8. 解决IDEA中自动生成返回值带final修饰的问题

    修改配置文件: Editor--Code Style--Java--Code Generation--将Make generated local variables final勾选上

  9. 解决ie低版本不认识html5标签

    在不支持HTML5新标签的浏览器里,会将这些新的标签解析成行内元素(inline)对待,所以我们只需要将其转换成块元素(block)即可使用,但是在IE9版本以下,并不能正常解析这些新标签,但是却可以 ...

  10. MySQL 的自增 ID 用完了,怎么办?

      一.简述 在 MySQL 中用很多类型的自增 ID,每个自增 ID 都设置了初始值.一般情况下初始值都是从 0 开始,然后按照一定的步长增加.在 MySQL 中只要定义了这个数的字节长度,那么就会 ...