文章

454

粉丝

0

获赞

1

访问

10.2k

头像
游侠UFO的战争游戏 题解(四语言 AC 代码)
P1115
发布于 2026年11月
阅读数 38

题意

炮弹以 45° 仰角发射,仅受重力 g=9.8 与水平风力加速度 a(顺风为正),求命中距离 L 处目标所需的初速度,保留 2 位小数。

思路

  • 飞行时间由竖直方向决定:t = 2·v·sin45°/g = √2·v/9.8。

  • 水平位移 = v·cos45°·t + a·t²/2 = v²/9.8 + a·v²/9.8²,合并得 L = v²·(9.8+a)/96.04。

  • 反解 v = sqrt(96.04·L/(9.8+a)),注意 a=-9.8 时公式退化(数据保证有解)。

  • L 可达 2e9,用 double 计算。

复杂度

时间 O(1) 每组,空间 O(1)。

参考代码(C / C++ / Java / Python)

C:

#include <stdio.h>
#include <math.h>
int main(void){long long L;int a;
while(scanf("%lld %d",&L,&a)==2){
if(L==0){printf("0.00\n");continue;}
printf("%.2f\n",9.8*sqrt((double)L/(9.8+a)));}return 0;}

C++:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){long long L;int a;
while(cin>>L>>a){if(L==0){printf("0.00\n");continue;}printf("%.2f\n",9.8*sqrt((double)L/(9.8+a)));}return 0;}

Java:

import java.io.*;
import java.util.*;
public class Main{
 public static void main(String[] z) throws IOException{
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  StringBuilder...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发