图形类题目
1 - 直角三角形
Problem:
思路
用pow平方的方法,避免开平方的精度损失
Code
#include<iostream>
#include<cmath>
using namespace std;
class CTriangle{
public :
//无参构造
CTriangle() {}
//有参构造
CTriangle(int x0,int y0,int x1,int y1,int x2,int y2) : x0(x0), y0(y0), x1(x1), y1(y1), x2(x2), y2(y2) {}
//方法
void isYN(){
//分别预测第三边
a = pow(x1 - x0, 2) + pow(y1 - y0, 2);
b = pow(x2 - x0, 2) + pow(y2 - y0, 2);
c = pow(x2 - x1, 2) + pow(y2 - y1, 2);
if(a + b == c || a + c == b || c + b == a){
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void len() {
printf("%.2lf\n", sqrt(a) + sqrt(b) + sqrt(c));
}
private:
int x0;
int y0;
int x1;
int y1;
int x2;
int y2;
double a;
double b;
double c;
};
int main(){
int n;
cin >> n;
while(n --){
int x0, y0, x1, y1, x2, y2;
cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2;
CTriangle ct(x0, y0, x1, y1, x2, y2);
ct.isYN();
ct.len();
}
return 0;
}