题目并不难,就是暴力,需要注意一下输出形式和精度。
#include<iostream> #include<cstdio> #include<cmath> using namespace std; #define maxn 100 #define jd 0.0001 double x[maxn],y[maxn],z[maxn],d,e,f; double getdis(double x,double y,double z,double x1,double y1,double z1) { return sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y) + (z1-z)*(z1-z)); } bool Judge(double a,double b,double c) { double ra1 = a/d; double ra2 = b/e; double ra3 = c/f; if(fabs(ra1-ra2)<jd && fabs(ra1-ra3)<jd && fabs(ra2-ra3)<jd) return true; return false; } int P,Q,R; bool Solve(double ij,double jk,double ik,int i,int j,int k) { if(Judge(ij,jk,ik)) {P = k; Q = i; R = j; return true;} if(Judge(ik,jk,ij)) {P = j; Q = i; R = k; return true;} if(Judge(ij,ik,jk)) {P = k; Q = j; R = i; return true;} if(Judge(jk,ik,ij)) {P = i; Q = j; R = k; return true;} if(Judge(ik,ij,jk)) {P = j; Q = k; R = i; return true;} if(Judge(jk,ij,ik)) {P = i; Q = k; R = j; return true;} return false; } int main() { int t,n; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf",&d,&e,&f); scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%lf%lf%lf",&x[i],&y[i],&z[i]); } int ans,tmp; for(int i = 1; i <= n; i++) { for(int j = i+1; j <= n; j++) { for(int k = j+1; k <= n; k++) { double ij = getdis(x[i],y[i],z[i],x[j],y[j],z[j]); double jk = getdis(x[j],y[j],z[j],x[k],y[k],z[k]); double ik = getdis(x[i],y[i],z[i],x[k],y[k],z[k]); if(Solve(ij,jk,ik,i,j,k) == true) { printf("%d %d %d\n",P,Q,R); } } } } } return 0; }
时间: 2024-12-15 18:30:00