NC14740. 小周的曲射炮
描述
输入描述
第一行为一个整数T,表示输入的数据组数。
每组数据对应一行输入, 依次为三个正整数x,y,v,含义如题面所示。
输出描述
每组数据输出一行,如果无论如何挑战炮口与地面夹角都无法将炮弹投射这目标处,输出“NO SOLUTION.”(不包括引号),否则从小到大输出所有可能的弧度(均四舍五入至小数点后5位,如果有两个解四舍五入至小数点后5位后相同,只视为一个解),中间用一个空格分隔。
示例1
输入:
4 45 56 78 32 78 55 33 33 25 12 25 25
输出:
0.93196 1.53271 1.24254 1.50973 NO SOLUTION. 1.25456 1.43951
C++(g++ 7.5.0) 解法, 执行用时: 2ms, 内存消耗: 480K, 提交时间: 2023-01-31 04:52:04
#include<cmath> #include<cstdio> int main() { int t;scanf("%d",&t); while(t--) { int x,y,v;scanf("%d%d%d",&x,&y,&v); double a=4.9*x*x/v/v,b=-x,c=a+y,delta=b*b-4*a*c; if(delta<0)puts("NO SOLUTION."); else if(delta<1e-11)printf("%.5lf\n",atan(-b/2/a)); else printf("%.5lf %.5lf\n", atan((-b-sqrt(delta))/2/a), atan((-b+sqrt(delta))/2/a)); } return 0; }
Python(2.7.3) 解法, 执行用时: 15ms, 内存消耗: 2944K, 提交时间: 2017-12-23 16:17:21
from math import atan for _ in xrange(input()): (x, y, v), g = map(float, raw_input().split()), 9.8 k = v ** 4 - g ** 2 * x ** 2 - 2 * g * y * v ** 2 if k < 0: print 'NO SOLUTION.' else: if not k: print '%.5f' % atan(v ** 2 / g * x) else: c = (v ** 2 - k ** .5) / (g * x) d = (v ** 2 + k ** .5) / (g * x) print '%.5f %.5f' % (atan(c), atan(d))
C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 384K, 提交时间: 2017-12-23 13:51:14
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { double x,y,v,s,r,t; cin>>x>>y>>v; s=(9.8*x*x/(v*v)+y)/pow(x*x+y*y,0.5); if(s>1)cout<<"NO SOLUTION."<<endl; else{ r=(asin(s)+atan(y/x))/2;t=(acos(-1)+atan(y/x)-asin(s))/2; if(r==t)cout<<setprecision(5)<<fixed<<r<<endl; else cout<<setprecision(5)<<fixed<<r<<" "<<t<<endl; } } }