UVa 10697 - Firemen barracks
来源:互联网 发布:有像皮影客类的软件 编辑:程序博客网 时间:2024/06/11 20:47
题目:已知三点,求到三点距离相同的点。
分析:计算几何。分三类情况讨论:
1.三点共线,不成立;
2.多点重叠,有多组解;
3.是三角形,输出中点。
说明:注意绝对值小于0.05的按0计算;负数的四舍五入与正数不同,-0.05的%.1lf输出是 -0.0。
#include <stdio.h>#include <stdlib.h>#include <math.h>double dist( double x0, double y0, double x1, double y1 ){return sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));}double deal( double x ){double esp = 1e-6;if ( x + esp < 0.05 && x - esp > -0.05 )return 0.0;else if ( x < 0.0 )return x - esp;else return x;}void calc( double x0, double y0, double x1, double y1, double x2, double y2 ){double a = dist( x0, y0, x1, y1 );double b = dist( x0, y0, x2, y2 );double c = dist( x2, y2, x1, y1 );if ( x0 == x1 && y1 == y0 || x0 == x2 && y2 == y0 || x2 == x1 && y1 == y2 ) {printf("There is an infinity of possible locations.\n");return;}if ( fabs(a-b-c) < 1e-9 || fabs(b-a-c) < 1e-9 || fabs(c-a-b) < 1e-9 ) {printf("There is no possible location.\n");return;}double A1 = x1-x0,B1 = y1-y0,C1 = x1*x1-x0*x0+y1*y1-y0*y0;double A2 = x2-x0,B2 = y2-y0,C2 = x2*x2-x0*x0+y2*y2-y0*y0;double X = (B1*C2-B2*C1)/(A1*B2-A2*B1)/-2.0;double Y = (A2*C1-A1*C2)/(A1*B2-A2*B1)/-2.0;printf("The equidistant location is (%.1lf, %.1lf).\n",deal(X),deal(Y));}int main(){int n;double x1,x2,x3,y1,y2,y3;while ( ~scanf("%d",&n) ) while ( n -- ) {scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);calc( x1, y1, x2, y2, x3, y3 );}return 0;}
0 0
- UVa 10697 - Firemen barracks
- Barracks at the base of mobile phones to read half the staff responsible for the content pipeline
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- css hack
- POJ 3255 Roadblocks 次短路
- C语言的本质(37)——makefile之隐含规则和模式规则
- My SQL的锁机制
- 深度解析CentOS通过日志反查入侵
- UVa 10697 - Firemen barracks
- 认识单例
- 结构
- 不用安装oracle客户端也可以用plsql连接远程oracle
- 有多少人能完全理解这篇文章里的话,有多少?
- Linux--无名管道pipe示例
- oracle 导入导出
- list使用中遇到的erase问题(List Iterator Not Incrementable)
- hdu-2519-新生晚会