Questions bees flying training algorithm
Resource constraints
Time limit: 1.0s memory limit: 512.0MB
description of the problem
, "two small bees ah, ah fly in the flowers ......"
Two bees flying around saying this every day, they jump in a strange dance. With a spatial rectangular coordinate system to describe the world, this two bees initial coordinates are (x1, y1, z1), (x2, y2, z2). In the following they will be n times the flight, the flight i respectively in accordance with their two bee flight speed vector ti units of time. For this phenomenon, WeiWeired has been observed for a long time. He would like to know when the bees flying in the end, how much distance two bees yes. Now he would ask for advice from you, please help him write a program to calculate the results.
Input format
of the first row and only one integer n, denotes the n times two bee flight.
Then there are n lines.
Seven i-th row are separated by spaces integers ai, bi, ci, di, ei, fi, ti, represents a first speed vector bees unit time (ai, bi, ci), a second bees speed vector unit time (di, ei, fi), which flight time is ti.
The last row of six integers separated by spaces x1, y1, z1, x2, y2, z2, as shown in the title represents the initial coordinates of two bees.
Output format
output contains only one line, the distance between the last two bees. Reserved 4 decimal places.
Sample input
the Sample. 1
. 1
. 1. 1. 1. 1. 1 2 -1
. 3. 1 0 0 0 2
the Sample 2
. 3
. 1. 1. 1. 1. 1 2 -1
2 -1 2 -1. 1 2 0
2 0 0 -1. 1. 1. 3
. 3 0 1200
Sample Output
Sample 1
4.2426
Sample 2
15.3948
Ideas: The first problem is calculated flight after n times, each time to multiplied by the flight distance and the original distance subtraction, two bees resulting x,, z-axis subtraction, addition after each square, square root then y the subject that is evaluated.
code show as below:
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
int n,i,j,a[10000][3],b[10000][3],t;
int x1,y1,z1,x2,y2,z2;
double sum;
cin>>n;
for(i=0;i<n;i++){
for(j=0;j<3;j++){
cin>>a[i][j];
}
for(j=0;j<3;j++){
cin>>b[i][j];
}
cin>>t;
for(j=0;j<3;j++){
a[i][j]*=t;
b[i][j]*=t;
}
}
cin>>x1>>y1>>z1>>x2>>y2>>z2;
for(i=0;i<n;i++){
x1+=a[i][0];y1+=a[i][1];z1+=a[i][2];
x2+=b[i][0];y2+=b[i][1];z2+=b[i][2];
}
sum=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
cout<<fixed<<setprecision(4)<<sqrt(sum);
}