输入第一行为样例数m,接下来m行每行6个整数分别表示三个点的横纵坐标。
对于每个样例输出两行,第一行根据是否直角三角形输出Yes或No,第二行输出三角形的周长,保留小数点后两位。
1 0 0 3 0 0 4
Yes 12.00
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
using namespace std;
class CTriangle{
public:
int x_1,x_2,x_3;
int y_1,y_2,y_3;
CTriangle()
{
}
CTriangle(int a,int b, int c, int d, int e ,int f)
{
this->x_1 = a;
this->y_1 = b;
this->x_2 = c;
this->y_2 = d;
this->x_3 = e;
this->y_3 = f;
}
double getDis(int a,int b,int c,int d)
{
return (sqrt(1.0*((a-c)*(a-c)) + 1.0*((b-d)*(b-d))));
}
void outPut()
{
double len_1 = getDis(x_1,y_1,x_2,y_2);
double len_2 = getDis(x_1,y_1,x_3,y_3);
double len_3 = getDis(x_2,y_2,x_3,y_3);
if(len_1 > len_3)
swap(len_1,len_3);
if(len_2>len_3)
swap(len_2,len_3);
if((len_1*len_1 + len_2 * len_2 == len_3 * len_3))
{
cout << "Yes" << endl;
}
else
cout << "No" << endl;
double ans = len_1 + len_2 + len_3;
printf("%.2lf\n",ans);
}
};
int main()
{
int n;
cin >> n;
for(int i = 0 ;i<n;i++)
{
int a,b,c,d,e,f;
cin >> a >> b >> c >> d >> e >> f;
CTriangle ans(a,b,c,d,e,f);
ans.outPut();
}
} #include<stdio.h>//1.求出三条边2.把最大边放在最后3.判断
#include<math.h>
int main()
{
int m,t,x1,x2,x3,y1,y2,y3,a,b,c;float d;
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
a=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);//三条边
b=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
c=(x3-x2)*(x3-x2)+(y3-y2)*(y3-y2);
d=sqrt(a)+sqrt(b)+sqrt(c);
if(a>b)//最大值放在c
{t=a;a=b;b=t;}
if(b>c)
{t=b;b=c;c=t;}
if(a+b==c)//判断直角
printf("Yes\n");
else
printf("No\n");
printf("%.2f\n",d);
}
}
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
for (int i = 0; i < m; i++) {
int x1 = scanner.nextInt();
int y1 = scanner.nextInt();
int x2 = scanner.nextInt();
int y2 = scanner.nextInt();
int x3 = scanner.nextInt();
int y3 = scanner.nextInt();
int[] edge = new int[3];
edge[0]= (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
edge[1]=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
edge[2]= (x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);
Arrays.sort(edge);
DecimalFormat f = new DecimalFormat("0.00");
System.out.println((edge[0]+edge[1])==edge[2]?"Yes":"No");
System.out.println(f.format(Math.sqrt(edge[0])+Math.sqrt(edge[1])+Math.sqrt(edge[2])));
}
}
} #include <stdio.h>
(737)#include <stdlib.h>
#include <math.h>
int main()
{
int n;
scanf("%d", &n);
while(n)
{
int str[10];
for(int i=0; i<6; i++)
scanf("%d", &str[i]);
int a = (str[0]-str[2])*(str[0]-str[2]) + (str[1]-str[3])*(str[1]-str[3]);
int b = (str[0]-str[4])*(str[0]-str[4]) + (str[1]-str[5])*(str[1]-str[5]);
int c = (str[2]-str[4])*(str[2]-str[4]) + (str[3]-str[5])*(str[3]-str[5]);
if(a+b == c || a+c == b || b+c == a)
printf("Yes\n");
else
printf("No\n");
printf("%.2lf\n", sqrt(a)+sqrt(b)+sqrt(c));
n--;
}
} #include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
int m;
cin>>m;
for(int n=0;n<m;n++){
int tri[6];
for(int i=0;i<6;i++)
cin>>tri[i];
double a,b,c;
a=sqrt((tri[0]-tri[2])*(tri[0]-tri[2])+(tri[1]-tri[3])*(tri[1]-tri[3]));
b=sqrt((tri[0]-tri[4])*(tri[0]-tri[4])+(tri[1]-tri[5])*(tri[1]-tri[5]));
c=sqrt((tri[4]-tri[2])*(tri[4]-tri[2])+(tri[5]-tri[3])*(tri[5]-tri[3]));
if(a>b&&a>c){
if(a*a==b*b+c*c)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else if(b>a&&b>c){
if(b*b==a*a+c*c)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
if(c>b&&c>a){
if(c*c==a*a+b*b)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
cout<<fixed<<setprecision(2)<<a+b+c<<endl;
}
}
#include<iostream>
#include<cmath>
using namespace std;
class CTriangle{
public:
int x1,x2,x3,y1,y2,y3;
CTriangle(int _1x,int _1y,int _2x,int _2y,int _3x,int _3y)
{
x1=_1x; y1=_1y;
x2=_2x; y2=_2y;
x3=_3x; y3=_3y;
}
void fun()
{
int d1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
int d2=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
int d3=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);
if(d1+d2==d3) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
double c=sqrt(d1)+sqrt(d2)+sqrt(d3);
printf("%.2f\n",c);
}
};
int main()
{
int m;
cin>>m;
for(int i=0;i<m;i++)
{
int x1,x2,x3,y1,y2,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
CTriangle c(x1,y1,x2,y2,x3,y3);
c.fun();
}
} #include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
float Length(float x1, float y1, float x2, float y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main() {
int m;
cin >> m;
while (m--) { // 注意 while 处理多个 case
float x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
float edge[3];
edge[0] = Length(x1, y1, x2, y2);
edge[1] = Length(x1, y1, x3, y3);
edge[2] = Length(x3, y3, x2, y2);
sort(edge, edge+3);
bool flag = (edge[0]*edge[0]+edge[1]*edge[1]) == (edge[2]*edge[2]);
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
cout << fixed << setprecision(2) << edge[0]+edge[1]+edge[2] << endl;
}
} #include<bits/stdc++.h>
using namespace std;
int main(){
int m;
cin>>m;
while(m--){
int x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
float l1=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
float l2=sqrt(pow(x3-x1,2)+pow(y3-y1,2));
float l3=sqrt(pow(x3-x2,2)+pow(y3-y2,2));
float a[3];
a[0]=l1,a[1]=l2,a[2]=l3;
sort(a,a+3);
if(pow(a[0],2)+pow(a[1],2)==pow(a[2],2)){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
printf("%.2f\n",l1+l2+l3);
}
return 0;
} #include <iostream>
#include <cmath>
using namespace std;
class CPoint {
public:
int x, y;
CPoint(int _x, int _y): x(_x), y(_y) {}
double operator-(CPoint& p) {
return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
};
class CTriangle {
public:
CPoint a, b, c;
CTriangle(int x1, int y1, int x2, int y2, int x3, int y3):
a(CPoint(x1, y1)), b(CPoint(x2, y2)), c(CPoint(x3, y3)) {}
void f() {
double s1 = a - b, s2 = b - c, s3 = a - c;
if ((s1 * s1 + s2 * s2 == s3 * s3) || (s1 * s1 + s3 * s3 == s2 * s2) ||
(s2 * s2 + s3 * s3 == s1 * s1))
cout << "Yes" << endl;
else
cout << "No" << endl;
printf("%.2lf\n", s1 + s2 + s3);
}
};
int main() {
int m;
cin >> m;
while (m--) {
int x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
CTriangle triangle(x1, y1, x2, y2, x3, y3);
triangle.f();
}
} #include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
class Point
{
public:
int x,y;
Point(){x=0;y=0;}
Point(int xx,int yy):x(xx),y(yy){}
};
class CTriangle
{
public:
Point a,b,c;
float l1,l2,l3;
CTriangle(){}
CTriangle(Point aa,Point bb,Point cc):a(aa),b(bb),c(cc){}
void getlength()
{
l1=sqrt(pow((a.x-b.x),2)+pow((a.y-b.y),2));
l2=sqrt(pow((a.x-c.x),2)+pow((a.y-c.y),2));
l3=sqrt(pow((c.x-b.x),2)+pow((c.y-b.y),2));
}
};
int main()
{
int m;
while(cin>>m)
{
while(m--)
{
int x1,x2,x3,y1,y2,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
Point a(x1,y1);
Point b(x2,y2);
Point c(x3,y3);
CTriangle t(a,b,c);
t.getlength();
if((pow(t.l1,2)+pow(t.l2,2)==pow(t.l3,2))||
(pow(t.l1,2)+pow(t.l3,2)==pow(t.l2,2))||
(pow(t.l3,2)+pow(t.l2,2)==pow(t.l1,2)))
{
cout<<"Yes"<<endl;
printf("%.2f\n",t.l1+t.l2+t.l3);
}
else
{
cout<<"No"<<endl;
printf("%.2f\n",t.l1+t.l2+t.l3);
}
}
}
} #include<iostream>
#include<cmath>
using namespace std;
class CPoint{
public:
int x,y;
CPoint(){}
CPoint(int x,int y){
this->x = x;
this->y = y;
}
float operator - (const CPoint A){
float d = 0;
d = (x-A.x)*(x-A.x) + (y-A.y)*(y-A.y);
d = sqrt(d);
return d;
}
};
class CTriangle{
public:
float x,y,z;
CTriangle(){};
CTriangle(CPoint x,CPoint y,CPoint z){
this->x = x - y;
this->y = y - z;
this->z = z - x;
}
void zhouchang(const CTriangle A){
float d= A.x + A.y + A.z;
if(A.x>=A.y && A.x>=A.z) {
if( A.x*A.x == A.y*A.y + A.z*A.z) {cout<<"Yes"<<endl; printf("%0.2f\n",d);}
else {cout<<"No"<<endl; printf("%0.2f\n",d);}
}
else if(A.y>=A.x && A.y>=A.z) {
if( A.y*A.y == A.x*A.x + A.z*A.z) {cout<<"Yes"<<endl; printf("%0.2f\n",d);}
else {cout<<"No"<<endl; printf("%0.2f\n",d);}
}
else {
if( A.z*A.z == A.x*A.x + A.y*A.y) {cout<<"Yes"<<endl; printf("%0.2f\n",d);}
else {cout<<"No"<<endl; printf("%0.2f\n",d);}
}
}
};
int main(){
int m;
while(cin>>m){
while(m--){
int x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
CPoint A(x1,y1);
CPoint B(x2,y2);
CPoint C(x3,y3);
CTriangle D(A,B,C);
D.zhouchang(D);
}
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
int m;
scanf("%d",&m);
int i,x1,y1,x2,y2,x3,y3;
double len1,len2,len3,temp;
for(i=0;i<m;i++){
scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3);
len1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
len2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
len3=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
if(len1>len2){
temp=len1;
len1=len2;
len2=temp;
}
if(len1>len3){
temp=len1;
len1=len3;
len3=temp;
}
if(len2>len3){
temp=len2;
len2=len3;
len3=temp;
}
if(len1+len2<=len3){
printf("No\n");
}
else{
if(len1*len1+len2*len2==len3*len3)
printf("Yes\n%.2f",len1+len2+len3);
else {
printf("No\n");
}
}
}
return 0;
} import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for (int i = 0; i < m; i++){
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int x3 = sc.nextInt();
int y3 = sc.nextInt();
point p1 = new point(x1, y1);
point p2 = new point(x2, y2);
point p3 = new point(x3, y3);
ctrangle1 c = new ctrangle1(p1, p2, p3);
c.isCtri();
}
sc.close();
}
}
class ctrangle1{
private point a1;
private point a2;
private point a3;
public ctrangle1(point a1, point a2, point a3) {
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
}
public void isCtri(){
double len12 = (Math.pow(a1.getX() - a2.getX(), 2) + Math.pow(a1.getY() - a2.getY(), 2));
double len23 = (Math.pow(a2.getX() - a3.getX(), 2) + Math.pow(a2.getY() - a3.getY(), 2));
double len31 = (Math.pow(a3.getX() - a1.getX(), 2) + Math.pow(a3.getY() - a1.getY(), 2));
double lenCircle = Math.sqrt(len12) + Math.sqrt(len23) + Math.sqrt(len31);
if (len12 + len23 == len31 || len23 + len31 == len12 || len31 + len12 == len23){
System.out.printf("Yes\n%.2f\n", lenCircle);
} else {
System.out.printf("No\n%.2f\n", lenCircle);
}
}
}
class point{
private int x;
private int y;
public point(){}
public point(int x, int y){
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
} #include<iostream>
(720)#include<cstdio>
#include<cmath>
using namespace std;
class CPoint{
private:
double x, y;
public:
CPoint(){}
CPoint(double a, double b):x(a),y(b){}
double operator - (CPoint & k);
};
double CPoint::operator - (CPoint & k){
double t=(k.x-this->x)*(k.x-this->x);
double p=(k.y-this->y)*(k.y-this->y);
return t+p;
}
class CTriangle{
private:
CPoint a,b,c;
public:
CTriangle(){}
CTriangle(CPoint x, CPoint y, CPoint z):a(x),b(y),c(z){}
void solve(){
double t1,t2,t3;
t1=a-b, t2=a-c, t3=b-c;
if( fabs(t1+t2-t3)< 1e-1 ||fabs(t1+t3-t2)<1e-6 ||fabs(t3+t2-t1)<1e-6){
printf("Yes\n%.2lf\n",sqrt(t1)+sqrt(t2)+sqrt(t3));
}
else printf("No\n%.2lf\n",sqrt(t1)+sqrt(t2)+sqrt(t3));
}
};
int main(){
int m;
double a,b,c,d,e,f;
cin>>m;
while(m--){
cin>>a>>b>>c>>d>>e>>f;
CPoint p(a,b),q(c,d),r(e,f);
CTriangle ans(p,q,r);
ans.solve();
}
return 0;
} #include<iostream>
(720)#include<cmath>
using namespace std;
class CPoint{
private:
int x;
int y;
public:
CPoint(int x,int y){
this->x=x;
this->y=y;
}
int operator-(CPoint c){
int dx=x-c.get_x();
int dy=y-c.get_y();
return dx*dx+dy*dy;
}
int get_x(){
return x;
}
int get_y(){
return y;
}
};
class CTriangle{
private:
CPoint a;
CPoint b;
CPoint c;
public:
CTriangle(int x1,int y1,int x2,int y2,int x3,int y3):a(x1,y1),b(x2,y2),c(x3,y3){}
CPoint get(int i){
if(i==1)
return a;
else if(i==2)
return b;
return c;
}
};
int main(){
int k,a,b,c,d,e,f;
cin>>k;
while(k-- >0){
cin>>a>>b>>c>>d>>e>>f;
CTriangle t(a,b,c,d,e,f);
CPoint c1=t.get(1);
CPoint c2=t.get(2);
CPoint c3=t.get(3);
int d1=c1-c2;
int d2=c1-c3;
int d3=c2-c3;
if(d1+d2==d3 || d1+d3==d2 || d2+d3==d1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
double len=sqrt(d1)+sqrt(d2)+sqrt(d3);
printf("%.2f\n",len);
}
return 0;
}
#include<stdio.h>
#include<math.h>
typedef struct
{
double x,y;
}dot;
double distance(dot a,dot b);
bool is90Triangle(dot a,dot b,dot c);
int main()
{
int m,i;
while(!scanf("%d",&m))
while(getchar()!='\n')
continue;
for(i=0;i<m;i++)
{
dot A,B,C;
scanf("%lf %lf %lf %lf %lf %lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
if(is90Triangle(A,B,C))
printf("Yes\n");
else
printf("No\n");
double l;
l=distance(A,B)+distance(A,C)+distance(B,C);
printf("%.2lf\n",l);
}
return 0;
}
double distance(dot a,dot b)
{
double result;
result=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
return result;
}
bool is90Triangle(dot a,dot b,dot c)
{
bool result=false;
double ab,ac,bc;
ab=distance(a,b);
ac=distance(a,c);
bc=distance(b,c);
if(ab>ac&&ab>bc)
{
double temp=(ab*ab)-(ac*ac+bc*bc);
if(fabs(temp)<1e-15)
result=true;
}
else if(ac>ab&&ac>bc)
{
double temp=(ac*ac)-(ab*ab+bc*bc);
if(fabs(temp)<1e-15)
result=true;
}
else if(bc>ac&&bc>ab)
{
double temp=(bc*bc)-(ab*ab+ac*ac);
if(fabs(temp)<1e-15)
result=true;
}
else
result=false;
return result;
} while True:
try:
m=int(input().strip())
for i in range(m):
x0,y0,x1,y1,x2,y2=map(int,input().strip().split(' '))
l1=((x0-x1)**2+(y0-y1)**2)**(0.5)
l2=((x0-x2)**2+(y0-y2)**2)**(0.5)
l3=((x2-x1)**2+(y2-y1)**2)**(0.5)
list1=sorted([l1,l2,l3])
if list1[0]**2+list1[1]**2==list1[2]**2:
print('Yes')
else:
print('No')
print('%.2f'%sum(list1))
except:
break