D. Tetragon
来源:互联网 发布:hadoop与java项目结合 编辑:程序博客网 时间:2024/06/05 18:35
You're given the centers of three equal sides of a strictly convex tetragon. Your task is to restore the initial tetragon.
The first input line contains one number T — amount of tests (1 ≤ T ≤ 5·104). Each of the followingT lines contains numbers x1, y1,x2, y2, x3,y3 — coordinates of different points that are the centers of three equal sides (non-negative integer numbers, not exceeding 10).
For each test output two lines. If the required tetragon exists, output in the first lineYES, in the second line — four pairs of numbers — coordinates of the polygon's vertices in clockwise or counter-clockwise order. Don't forget, please, that the tetragon should be strictly convex, i.e. no 3 of its points lie on one line. Output numbers with 9 characters after a decimal point.
If the required tetragon doen't exist, output NO in the first line, and leave the second line empty.
31 1 2 2 3 30 1 1 0 2 29 3 7 9 9 8
NOYES3.5 1.5 0.5 2.5 -0.5 -0.5 2.5 0.5NO
解释:
设ABCD是所寻求的四边形,和K,L和M是相等的边AB,BC和CD,相应的中间点。让,M'是对称的点相对于L。然后BM'=CM = CL = BL =BK,我到M。 E。 B是三角形的KLM'外心。
了解B,我们可以得到整个四合院,使用的对称性点,K,L和M,然后检查它是否满足所有的条件。
需要注意的是,我们不知道哪一个给定的点是L,所以我们需要检查所有的3起案件。
代码:
#include <iostream>#include <sstream>#include <string>#include <vector>#include <deque>#include <queue>#include <set>#include <map>#include <algorithm>#include <functional>#include <utility>#include <cmath>#include <cstdlib>#include <ctime>#include <cstdio>using namespace std;#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)struct point{ double x,y;};#define eps 1.0E-9#define _abs(x) ((x)>0?(x):-(x))double area(point P, point Q, point R){ return ((Q.x - P.x) * (R.y - P.y) - (Q.y - P.y) * (R.x - P.x)) / 2.0;}point cross(point A, point B, point C, point D) // AB - CD{ double a = -A.y + B.y, b = A.x - B.x, c = A.x * B.y - A.y * B.x, d = -C.y + D.y, e = C.x - D.x, f = C.x * D.y - C.y * D.x; point ans = {(c*e - b*f) / (a*e - b*d), (c*d - a*f) / (b*d - a*e)}; return ans;}point func4(point &P, point &M){ point ans = {M.x * 2 - P.x, M.y * 2 - P.y}; return ans;}point func3(point &A, point &B){ double dx = B.x - A.x, dy = B.y - A.y; point ans = {A.x + dx / 2.0 - dy / 2.0, A.y + dy / 2.0 + dx / 2.0}; return ans;}vector <point> func2(point A, point B, point C){ point D,E,F,G; point H = func3(A,B), I = func3(B,A); double dx = B.x - A.x, dy = B.y - A.y; H.x += dx; H.y += dy; I.x += dx; I.y += dy; point J = func3(B,C), K = func3(C,B); E = cross(H,I,J,K); D = func4(E,C); F = func4(E,B); G = func4(F,A); vector <point> ans; double tmp; bool pos = false, neg = false; tmp = area(D,E,F); if(tmp > -eps) pos = true; if(tmp < eps) neg = true; tmp = area(E,F,G); if(tmp > -eps) pos = true; if(tmp < eps) neg = true; tmp = area(F,G,D); if(tmp > -eps) pos = true; if(tmp < eps) neg = true; tmp = area(G,D,E); if(tmp > -eps) pos = true; if(tmp < eps) neg = true; if(pos && neg) return ans; ans.push_back(D); ans.push_back(E); ans.push_back(F); ans.push_back(G); return ans;}vector <point> func(point A, point B, point C){ vector <point> ans; if(_abs(area(A,B,C)) < eps) return ans; ans = func2(A,B,C); if(!ans.empty()) return ans; ans = func2(B,C,A); if(!ans.empty()) return ans; ans = func2(C,A,B); if(!ans.empty()) return ans; return ans;}int main(void){ int T,t,i; point A,B,C; scanf("%d",&T); REP(t,T) { scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y); vector <point> ans = func(A,B,C); if(!ans.empty()) printf("YES\n"); else printf("NO\n"); REP(i,ans.size()) { printf("%.9f %.9f",ans[i].x,ans[i].y); if(i != ans.size() - 1) printf(" "); } printf("\n"); } return 0;}
- D. Tetragon
- Codeforences 23D Tetragon
- CodeForces 23D Tetragon 给定凸四边形3条同边长的中点求4个顶点 计算几何
- d
- d
- d
- d
- d
- D
- d
- d
- d
- d
- d
- %d
- d
- d
- d
- hibernate缓存
- 嵌入式中程序升级,使用ftp shell脚本,方式
- 几个重要平台的auth2登录验证
- linux 与汇编语言
- Xcode工程添加第三方文件的详细分析 Create folder references for any added folders
- D. Tetragon
- .NET 网站自动登录
- 用SecureCRT来上传和下载文件
- C#网络编程系列一:网络协议简介
- Spring中配置数据源的4种形式
- linux chmod命令
- allegro出异形空错误总结
- tar命令
- chgrp命令