Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的程序如下,谁帮我看看那个bt数据过不去 谢谢了In Reply To:数据太bt了 Posted by:first at 2006-12-18 10:26:11 #include <iostream> #include <sstream> #include <fstream> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <set> #include <map> #include <vector> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; long double line1[2][3]; long double line2[2][3]; long double xyz[3]; long double d; long double start[3]; long double end[3]; long double AB; #define eps 1e-10 long double distance(long double *p1, long double *p2) { return sqrt(pow(p1[0] - p2[0], 2) + pow(p1[1] - p2[1], 2) + pow(p1[2] - p2[2], 2)); } long double jumpdis(long double *p) { long double PA = distance(p, line2[0]); long double PB = distance(p, line2[1]); if(PA*PA < PB*PB + AB*AB && PB*PB < PA*PA + AB*AB) { long double l = (PA + PB + AB)/2; long double S = sqrt(abs((l - PA)*(l - PB)*(l - AB)*l)); return 2*S/AB; } return min(PA, PB); } void input() { scanf("%lf %lf %lf", &line1[0][0], &line1[0][1], &line1[0][2]); scanf("%lf %lf %lf", &line1[1][0], &line1[1][1], &line1[1][2]); scanf("%lf %lf %lf", &line2[0][0], &line2[0][1], &line2[0][2]); scanf("%lf %lf %lf", &line2[1][0], &line2[1][1], &line2[1][2]); scanf("%lf %lf %lf", &xyz[0], &xyz[1], &xyz[2]); scanf("%lf", &d); } long double solve() { long double len1 = distance(line1[0], line1[1]); long double dir[3]; dir[0] = (line1[0][0] - line1[1][0])/len1; dir[1] = (line1[0][1] - line1[1][1])/len1; dir[2] = (line1[0][2] - line1[1][2])/len1; bool flag1 = false, flag2 = false; int i; for(i = 0; i < 3; i ++) { start[i] = xyz[i] + d*dir[i]; if(dir[i]*(line1[0][i] - start[i]) < 0) flag1 = true; end[i] = xyz[i] - d*dir[i]; if(dir[i]*(line1[1][i] - end[i]) > 0) flag2 = true; } if(flag1) { for(i = 0; i < 3; i ++) start[i] = line1[0][i]; } if(flag2) { for(i = 0; i < 3; i ++) end[i] = line1[1][i]; } AB = distance(line2[0], line2[1]); long double l = 0, r = 1; long double m1[3], m2[3]; long double mr1, mr2; while(r - l > eps) { mr1 = (2*l + r)/3.0; mr2 = (l + 2*r)/3.0; for(i = 0; i < 3; i ++) { m1[i] = (1 - mr1)*start[i] + mr1*end[i]; m2[i] = (1 - mr2)*start[i] + mr2*end[i]; } if(jumpdis(m1) < jumpdis(m2)) { r = mr2; } else { l = mr1; } } mr1 = (l + r)/2; for(i = 0; i < 3; i ++) { m1[i] = (1 - mr1)*start[i] + mr1*end[i]; } return jumpdis(m1); } int main() { input(); printf("%.3lf\n", solve()); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator