zoukankan      html  css  js  c++  java
  • 算法训练 蜜蜂飞舞

      算法训练 蜜蜂飞舞  
    时间限制:1.0s   内存限制:512.0MB
        
    问题描述
      “两只小蜜蜂呀,飞在花丛中呀……”

      话说这天天上飞舞着两只蜜蜂,它们在跳一种奇怪的舞蹈。用一个空间直角坐标系来描述这个世界,那么这两只蜜蜂初始坐标分别为(x1,y1,z1),(x2,y2,z2)  。在接下来它们将进行n次飞行,第i次飞行两只蜜蜂分别按照各自的速度向量飞行ti个单位时间。对于这一现象,玮玮已经观察了很久。他很想知道在蜜蜂飞舞结束时,两只蜜蜂的距离是多少。现在他就求教于你,请你写一个程序来帮他计算这个结果。
    输入格式
      第一行有且仅有一个整数n,表示两只蜜蜂将进行n次飞行。

      接下来有n行。

      第i行有7个用空格分隔开的整数ai,bi,ci,di,ei,fi,ti  ,表示第一只蜜蜂单位时间的速度向量为(ai,bi,ci) ,第二只蜜蜂单位时间的速度向量为(di,ei,fi) ,它们飞行的时间为ti 。

      最后一行有6个用空格分隔开的整数x1,y1,z1,x2,y2,z2,如题所示表示两只蜜蜂的初始坐标。
    输出格式
      输出仅包含一行,表示最后两只蜜蜂之间的距离。保留4位小数位。
    样例输入
    Sample 1
    1
    1 1 1 1 -1 1 2
    3 0 1 2 0 0
    Sample 2
    3
    1 1 1 1 -1 1 2
    2 1 2 0 -1 -1 2
    2 0 0 -1 1 1 3
    3 0 1 2 0 0

    样例输出

    Sample 1
    4.2426
    Sample 2
    15.3948

    import java.util.Scanner;
    public class Main {
        
        public static void main(String [] args){
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int [][]v=new int[n][7];
            int buffer1[]=new int[3];
            int buffer2[]=new int[3];
            for(int i=0;i<n;i++){
                for(int j=0;j<7;j++){
                    v[i][j]=sc.nextInt();
                }
            }
            for(int i=0;i<3;i++) buffer1[i]=sc.nextInt();
            for(int i=0;i<3;i++) buffer2[i]=sc.nextInt();
            int temp1=0;
            int temp2=0;
            int temp3=0;
                for(int i=0;i<n;i++){
                    temp1+=v[i][0]*v[i][6];  
                    temp2+=v[i][1]*v[i][6];  
                    temp3+=v[i][2]*v[i][6];  
            }
                int tmp1=0;
                int tmp2=0;
                int tmp3=0;
                for(int i=0;i<n;i++){
                    tmp1+=v[i][3]*v[i][6];
                    tmp2+=v[i][4]*v[i][6];
                    tmp3+=v[i][5]*v[i][6];
                }
                  int sx1=buffer1[0]+temp1;
                  int sy1=buffer1[1]+temp2;
                  int sz1=buffer1[2]+temp3;
                  
                  int sx2=buffer2[0]+tmp1;
                  int sy2=buffer2[1]+tmp2;
                  int sz2=buffer2[2]+tmp3;
                  
                  double sx=Math.abs(sx1-sx2);
                  double sy=Math.abs(sy1-sy2);
                  double sz=Math.abs(sz1-sz2);
                  
                  double ans=Math.sqrt(sx*sx+sy*sy+sz*sz);
                  System.out.printf("%.4f", ans);
        }
    
    }
    
    
    
     
  • 相关阅读:
    〖Linux〗Kubuntu设置打开应用时就只在打开时的工作区显示
    〖Linux〗Kubuntu, the application 'Google Chrome' has requested to open the wallet 'kdewallet'解决方法
    unity, dll is not allowed to be included or could not be found
    android check box 自定义图片
    unity, ios skin crash
    unity, Collider2D.bounds的一个坑
    unity, ContentSizeFitter立即生效
    类里的通用成员函数应声明为static
    unity, Gizmos.DrawMesh一个坑
    直线切割凹多边形
  • 原文地址:https://www.cnblogs.com/watchfree/p/5436478.html
Copyright © 2011-2022 走看看