[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; 
}
posted @ 2019-07-15 15:43  LinZhengmin  阅读(152)  评论(0编辑  收藏  举报

Contact with me