前言

今天又是爆零的一天。

被同学坑了,还以为四边形的点是按任意序给定的,然后打了一个特别复杂的矩形判断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. unity让碰撞只发生一次

    碰撞发生在帧的开始,所以你可以检测到冲突,并在LateUpdate复位: private bool hasCollided = false; void OnCollisionEnter(Collisi ...

  2. 面试题:线程A打印1-10数字,打印到第5个数字时,通知线程B

    此题考查的是线程间的通信方式. 可以利用park/unpark实现 可以利用volatile关键字实现 可以利用synchronized结合wait notify实现 可以利用JUC中的CountDo ...

  3. 006 Notepad++ 运行 C/C++

    目录 0. 前言 1. 准备 2. 开工 setp 1 step 2 step 3 step 4 step 5 step 6 3. 修改与删除 3.1修改名称.快捷键 3.2 删除 4. 运行 5. ...

  4. [Git] 022 没有人是一座孤岛

    0.回顾 [Git] 015 远程仓库篇 第二话 关联与推送 的 "2" 中介绍过 git remote git remote -v 与 "status" 不同 ...

  5. Java 5种单例模式

    /*单例模式: 指某个类中只能存在一个对象实例,并且该类中只提供一个取得其对象实例的方法 优点:减少系统性能开销 应用场景:网站的计数器,任务管理器,回收站等*/   //单例模式1 -- 静态内部类 ...

  6. P1067多项式输出

    这道题是2009普及组的题,仍然是一个字符串+模拟.(蒻到先不刷算法) 这道题的题干给了很多的提示,也很全面,但是当我把种种情况都考虑到了后,在写代码的过程中仍然出现了很多的错误,wa了三四次.其实导 ...

  7. C++ 统计输入的句子有多少英文字母

    // ConsoleApplication1.cpp: 定义控制台应用程序的入口点.//#include "stdafx.h"#include <iostream>#i ...

  8. 创建MySQL数据库账号

    为本项目创建数据库用户(不再使用root账户) create user 账号 identified by '密码'; grant all on 数据库.* to '用户'@'%'; flush pri ...

  9. 3.css3中多个背景图片的用法

    (background-clip裁剪,background-position位置,background-origin定位,background-repeat是否重复) <!DOCTYPE htm ...

  10. 50. Pow(x, n) (JAVA)

    Implement pow(x, n), which calculates x raised to the power n(xn). Example 1: Input: 2.00000, 10 Out ...