NC222978. Triangle
描述
输入描述
The first line contains a positive integer T.
For each case, there will be six lines,each lines contain two integers,means the x, y coordinates of points.
And the first three lines are the vertexs of the first triangle.
The second three lines are the vertexs of the first triangle.
输出描述
For each case ,if two triangles are similar then print "YES",else print "NO".
示例1
输入:
2 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 1 1 0 2 2 2 0 1 0
输出:
YES NO
C++ 解法, 执行用时: 17ms, 内存消耗: 384K, 提交时间: 2021-06-19 16:26:39
#include <bits/stdc++.h> using namespace std; typedef long double db; db a[10]; db b[10]; struct node { db x,y; void input(){ cin>>x>>y; } }A,B,C,AA,BB,CC; db dis(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } int main() { int T; cin>>T; while(T--) { A.input(); B.input(); C.input(); AA.input(); BB.input(); CC.input(); a[1]=dis(A,B); a[2]=dis(B,C); a[3]=dis(A,C); b[1]=dis(AA,BB); b[2]=dis(BB,CC); b[3]=dis(AA,CC); sort(a+1,a+4); sort(b+1,b+4); db gl=a[1]/b[1]; if(a[2]/b[2]==gl && a[3]/b[3]==gl) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }