HDOJ 5144 NPY and shot 简单物理

三分角度....

NPY and shot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 236    Accepted Submission(s): 87

Problem Description

NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw
?(The acceleration of gravity, g, is $9.8m/s^2$)

Input

The first line contains a integer $T(T \leq 10000)$,which indicates the number of test cases.

The next T lines,each contains 2 integers $H(0 \leq h \leq 10000m)$,which means the height of NPY,and $v_0(0 \leq v_0 \leq 10000m/s)$, which means the initial velocity.

Output

For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.

Sample Input

2
0 1
1 2

Sample Output

0.10
0.99

Hint

If the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.

Source

BestCoder Round #22

/* ***********************************************
Author        :CKboss
Created Time  :2014年12月13日 星期六 23时27分32秒
File Name     :C.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const double eps=1e-6;
const double g=9.8;

double H,V;

double Distan(double degree)
{
	double vx=V*sin(degree);
	double vy=V*cos(degree);

	double time = ( vx+sqrt(vx*vx+2*g*H) ) / g;

	return time*vy;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	int T_T;
	scanf("%d",&T_T);
	while(T_T--)
	{
		scanf("%lf%lf",&H,&V);

		double low=0.,high=90.;
		double mid1,mid2,ans=0;

		while(fabs(high-low)>=eps)
		{
			mid1=(low*2+high)/3.;
			mid2=(low+high*2)/3.;

			double len1=Distan(mid1);
			double len2=Distan(mid2);

			ans=max(ans,max(len1,len2));

			if(len2+eps>len1)
				low=mid1;
			else high=mid2;
		}

		printf("%.2lf\n",ans);
	}
    return 0;
}
时间: 2024-12-27 18:07:11

HDOJ 5144 NPY and shot 简单物理的相关文章

hdu 5144 NPY and shot

http://acm.hdu.edu.cn/showproblem.php?pid=5144 题意:给你初始的高度和速度,然后让你求出水平的最远距离. 思路:三分枚举角度,然后根据公式求出水平距离. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 const double pi=acos(-1

HDU 5144 NPY and shot(三分法)

当时做这道题时一直想退出物理公式来,但是后来推到导数那一部分,由于数学不好,没有推出来那个关于Θ的最值,后来直接暴力了,很明显超时了,忘了三分法的应用,这道题又是典型的三分求最值,是个单峰曲线,下面是代码 1 #include <stdio.h> 2 #include <math.h> 3 #define PI 3.1415926 4 int v, h; 5 double f(double i)//推倒物理公式 6 { 7 return v*v*1.0*sin(2*i)/9.8+(

HDU 2529 Shot (物理数学题)

题目 解题过程: //物理数学题 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { double h,l,v,ans; while(scanf("%lf%lf%lf",&h,&l,&v)!=EOF) { if(h==0&&l==0&&v==0)break; ans

BestCoder22 1003.NPY and shot 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144 题目意思:有个人抛物体,已知抛的速度和高度,问可以抛到的最远距离是多少.即水平距离. 做的时候是抄公式的,居然过了,幸运幸运............ 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <algorit

HDOJ 5142 NPY and FFT 水

比赛的时候题目意思完全不对.....居然还有人1分钟就AC了...... NPY and FFT Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 132    Accepted Submission(s): 86 Problem Description A boy named NPY is learning FFT algorithm

HDOJ 5143 NPY and arithmetic progression DFS

DFS..... 多余3个的数可以自己成等比数列 和其他数组合成等比数列的有1,2,3,  2,3,4  1,2,3,4 三种情况 NPY and arithmetic progression Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 189    Accepted Submission(s): 61 Problem Descri

HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题. 亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串. Input 本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二

hdoj - 1258 Sum It Up &amp;&amp; hdoj - 1016 Prime Ring Problem (简单dfs)

http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. 1 #include <cstdio> 2 #include <cstring> 3 4 int n,t; 5 int b[15],c[15]; 6 bool flag; 7 void dfs(int k,int sum,int l) 8 { 9 if(sum==t) 10 { 11 for(int i=0;i<l-1;i++) 12 p

HDOJ 1339 A Simple Task(简单数学题,暴力)

Problem Description Given a positive integer n and the odd integer o and the nonnegative integer p such that n = o2^p. Example For n = 24, o = 3 and p = 3. Task Write a program which for each data set: reads a positive integer n, computes the odd int