Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求助大佬,帮忙看一下哪里错了

Posted by eraser_ruler at 2023-01-18 10:13:47 on Problem 3684
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double g = 10.0;
		int count = sc.nextInt();
		int index = 0;
		while(index<count) {
			int N = sc.nextInt();	//球个数
			int H = sc.nextInt();	//高度
			int R = sc.nextInt();	//半径
			int T = sc.nextInt();	//时间
			double[] wz = new double[N];	//每个球的位置
			if(T < 0) {
				for(int i =0 ; i < N; i++)
					System.out.printf("%.2f ",H+2*R*i/100.0);
				index++;
				continue;
			}
			for(int i = 0; i < N; i++) {	//遍历每个球
				int Ti = T - i;	//每个球的所拥有的总时间不一样。因为隔一秒下落一个
				double h = H;// + 2*R
				double t = Math.sqrt(2*h/g);	
				int k = (int)(Ti / t);	//往返了多少次 
				//System.out.println("Ti:"+Ti+" h:"+h+" t:"+t+" k:"+k);
				if(k%2==0) {	//为偶数说明一个来回,且当前在下降
					wz[i] = h - g*(Ti - k*t)*(Ti - k*t)/2;	//g*(Ti - k*t)*(Ti - k*t)/2算的是下落的距离,问的是离地面的距离
				}else {	//为偶数说明没完成一个来回,且当前在上升
					//此时的位置可以假设是从上面初速度为0掉下来的,时间就是kt+t-Ti	算出来是下落的距离
					wz[i] = h - g*(k*t + t - Ti)*(k*t + t - Ti)/2;
				}
			}
			index++;
			
			Arrays.sort(wz);
			for(int i = 0; i < N; i++) {	//打印输出
				System.out.printf("%.2f ",wz[i]+2*R*i/100.0);
			}
		}
		
		

	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator