URAL 1963 Kite 四边形求对称轴数
题目链接: http://acm.timus.ru/problem.aspx?space=1&num=1963
题意,顺时针或逆时针给定4个坐标,问对称轴有几条,输出(对称轴数*2)
对于一条对角线,若他是对称轴,必须满足:另外2点关于这条对角线对称 =》 2条对角线互相垂直且 与这条对角线形成的夹角相等
而对于每条边的中点,只需要证明中点相连后与其所在的边垂直即可,垂直且相等就可以证明是对称的
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <set>
#include <vector>
#define eps 1e-8
#define N 10
using namespace std; struct point {
double x,y;
}p[N]; bool eq(double a,double b){return (a-b>0?a-b:b-a)<eps;} bool chuizhi(point a,point b,point c,point d){
if(!eq(a.x,b.x) && !eq(c.x,d.x))
return eq(((a.y-b.y)*(c.y-d.y))/((a.x-b.x)*(c.x-d.x)),-1);
if(eq(a.x,b.x))return eq(c.y,d.y);
if(eq(c.x,d.x))return eq(a.y,b.y);
}
double dis(point a,point b){ return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));}
double du(point a,point b,point c){
double d1=dis(a,b),d2=dis(b,c),d3=dis(c,a);
return (d1*d1+d3*d3-d2*d2)/d1*d3;
}
double k(point a,point b){//斜率
if(a.x==b.x)return 456453454154.154674;
return (a.y-b.y)/(a.x-b.x);
}
bool jiaodu(point a,point b,point c,point d)//a能否作为答案
{//a,b对边 c,d对边
point temp={(c.x+d.x)/2,(c.y+d.y)/2};
if(eq(k(a,b),k(a,temp)))return true;
return false;
}
void zhongdian(){
p[4].x=(p[0].x+p[1].x)/2,p[4].y=(p[0].y+p[1].y)/2;
p[5].x=(p[1].x+p[2].x)/2,p[5].y=(p[1].y+p[2].y)/2;
p[6].x=(p[2].x+p[3].x)/2,p[6].y=(p[2].y+p[3].y)/2;
p[7].x=(p[3].x+p[0].x)/2,p[7].y=(p[0].y+p[3].y)/2;
}
int main() {
while (scanf ("%lf%lf", &p[0].x, &p[0].y) != EOF) {
for (int i=1; i<4; ++i) scanf ("%lf%lf", &p[i].x, &p[i].y);
int ans=0;
zhongdian(); if(chuizhi(p[0],p[2],p[1],p[3])&& jiaodu(p[0],p[2],p[1],p[3]))ans++;
if(chuizhi(p[1],p[3],p[0],p[2])&& jiaodu(p[1],p[3],p[0],p[2]))ans++;
if(chuizhi(p[4],p[6],p[0],p[1]) && chuizhi(p[4],p[6],p[2],p[3]))ans++;
if(chuizhi(p[5],p[7],p[0],p[3]) && chuizhi(p[5],p[7],p[1],p[2]))ans++;
printf("%d\n",ans*2);
}
return 0;
} /*
0 0
0 9999
9999 9999
9999 0 0 0
1 2
2 2
2 1 ans:
8
2 */
URAL 1963 Kite 四边形求对称轴数的更多相关文章
- URAL 1963 Kite 计算几何
Kite 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/C Description Vova bought a kite con ...
- 帮初学者改代码——playerc之“练习:求完数问题”(下)
前文链接:帮初学者改代码——playerc之“练习:求完数问题”(上) 再来看看be_ferfect()应该如何改. be_ferfect()函数的功能是判断number是否为完数,同时把因子对写入d ...
- 帮初学者改代码——playerc之“练习:求完数问题”(上)
原文:“练习:求完数问题” 原代码: // #include <stdio.h> #include <stdlib.h> #include <math.h> #de ...
- openmp 并行求完数
// GetWanShu.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "omp.h" #inclu ...
- d008: 求两数的整数商 和 商
内容: 求两数的整数商 和 商 ,商保留两位小数 输入说明: 一行 两个整数 输出说明: 一行,一个整数,一个实数(两位小数) 输入样例: 12 8 输出样例 : 1 1.50 #include ...
- d007: 求两数的整数商 和 余数
内容: 求两数的整数商 和 余数 输入说明: 一行两个整数 输出说明: 一行两个整数 输入样例: 18 4 输出样例 : 4 2 #include <stdio.h> int main ...
- ZOJ3574(归并排序求逆数对)
Under Attack II Time Limit: 5 Seconds Memory Limit: 65536 KB Because of the sucessfully calcula ...
- 求数组的最小数、最大值,求一组数的平均数,sort函数详解,类数组转数组
求数组的最小值和最大值 //求数组当中最大值和最小值 var arr=[3,2,6,1,45,23,456,23,2,6,3,45,37,89,30]; //第一种方法 根据排序方法来求最大值和最小值 ...
- Jsの数组练习-求一组数中的最大值和最小值,以及所在位置
要求:求一组数中的最大值和最小值,以及所在位置 代码实现: <!DOCTYPE html> <html lang="en"> <head> &l ...
随机推荐
- POJ 2455 网络流 基础题 二分+网络流 dicnic 以及 sap算法
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8189 Accepted: ...
- C#游戏框架uFrame
C#游戏框架uFrame兼谈游戏架构设计 c#语言规范 阅读目录 1.概览 2.基本概念 3.依赖注入 4.Manager of Managers 5.利用UniRX实现响应式编程 6.研究总结 回到 ...
- QT之深入理解QThread
QT之深入理解QThread 理解QThread之前需要了解下QThread类,QThread拥有的资源如下(摘录于QT 5.1 帮助文档): 在以上资源中,本文重点关注槽:s ...
- static在C和C++中的用法和区别
static主要有三个作用: (1)局部静态变量 (2)外部静态变量/函数 (3)静态数据成员/成员函数 前两种C和C++都有,第三种仅在C++中有,下面分别作以下介绍: 一.局部静态变量 在C/C+ ...
- 基于visual Studio2013解决面试题之0808寻找中间数
题目
- hdu5338 ZZX and Permutations
hdu5338 ZZX and Permutations 非原创,来自多校题解 不是自己写的,惭愧ing…… 留着以后自己参考…… lower_bound {1,2,4,5} 询问 2,返回的是 2 ...
- 操作系统栈溢出检測之ucosII篇
操作系统栈溢出检測之uc/osII篇 Author : David Lin (林鹏) E-mail : linpeng1 ...
- var, object, dynamic的区别以及使用(转载)
var, object, dynamic的区别以及使用 阅读目录: 一. 为什么是它们三个 二. 能够任意赋值的原因 三. dynamic的用法 四. 使用dynamic的注意事项 拿这三者比较的原因 ...
- [jQuery] check if an id exists - Google 网上论坛
[jQuery] check if an id exists - Google 网上论坛 From: http://docs.jquery.com/Frequently_Asked_Questions ...
- 我在北京找工作(五):备战阿里巴巴java笔试<1>:筑基
@@@2013年9月11日 还在北京昌平区@@@ 好几天没有往博客上贴我的面试备战笔记了,今天开始分享一下备战阿里巴巴校招的笔经,当然重点是java方向的题目~. 插一段2014年阿里巴巴校招的消息: ...