Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5144
The title means: there is a person throwing objects, known to throw the speed and height, ask what the farthest distance can be thrown. That is, the horizontal distance.
The time to do is to copy the formula, incredibly past, lucky lucky ...
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <algorithm>6 using namespacestd;7 8 Const Doubleg =9.8;9 Ten intMain () One { A intT; - Doubleh, v; - while(SCANF ("%d", &t)! =EOF) the { - while(t--) - { -scanf"%LF%LF", &h, &v); + DoubleTMP = sqrt (v*v + 1ll *2* g *h); - Doublet = tmp/G; + DoubleAns = t *v; Aprintf"%.2lf\n", ans); at } - } - return 0; -}
View Code
Udong do more formal, is done with three points, and floating-point precision control, it is worth learning ^_^ (without his permission to steal his copyright, should not blame me ...) )
1#include <algorithm>2#include <cstdio>3#include <cstdlib>4#include <cmath>5#include <iostream>6#include <map>7#include <numeric>8#include <vector>9 Ten using namespacestd; One A Const DoubleEPS = 1e-8; - Const DoublePI = ACOs (-1.0); - Const DoubleG =9.8; the - inth, v; - - DoubleFDoubleang) + { - DoubleHV = cos (ANG) *v; + Doublevv = sin (ANG) *v; A DoubleT1 = vv/G; at Doublet2 = sqrt (2* (vv*t1-g*t1*t1/2.0+H)/G); - returnhv* (t1+T2); - } - - intMain () - { in intKase; -scanf"%d", &Kase); to while(kase--) { +scanf"%d%d", &h, &v); - DoubleL =0.0, R = pi/2; the while(L < REPS) { * DoubleD = (r-l)/3.0; $ DoubleLL = L +D;Panax Notoginseng DoubleRR = RD; - if(F (LL) <F (RR)) theL =ll; + Else AR =RR; the } +printf"%.2f\n", F (L)); - } $ return 0; $}
BestCoder22 1003.NPY and shot Problem solving report