Toxophily-数论以及二分三分
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
cid=83980#status//G/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">Status
id=19904" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">Practice
HDU2298
Description
We all like toxophily.
Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?
Now given the object's coordinates, please calculate the angle between the arrow and x-axis at Bob's point. Assume that g=9.8N/m.
Input
indicate the coordinate of the fruit. v is the arrow's exit speed.
Technical Specification
1. T ≤ 100.
2. 0 ≤ x, y, v ≤ 10000.
Output
Output "-1", if there's no possible answer.
Please use radian as unit.
Sample Input
3
0.222018 23.901887 121.909183
39.096669 110.210922 20.270030
138.355025 2028.716904 25.079551
Sample Output
1.561582
-1
-1
设vx=v*cos(α),vy=v*sin(α),同一时候从P(0,0)点到达目标点花了t时间,重力加速度为G=9.8.
∴x=vx*t,y=vy*t-1/2*G*t².
消掉vx,vy,t能够转换为y=v*sin(α)*x/(v*cos(α))-1/2*g*x²/(v²*cos(α)²).
∴将sin(α)/cos(α)=tan(α);
∴y=v*x*tan(α)-(1/2*g*x²/v²)*((sin(α)²+cos(α)²)/cos(α)²);
∴y=v*x*tan(α)-(1/2*g*x²/v²)*(1+tan(α)²);
∴将其进行整理能够得到:g*x²*tan(α)²-2*v²*x*tan(α)+2*v²y+g*x²=0;
∴能够得到△=b²-4*a*c;
∴令a=g*x²,b=-2*v²*x,c=2*v²y+g*x².
又∵x1=(-b+(b²-4*a*c)½)/(2*a),x2=(-b-(b²-4*a*c)½)/(2*a).
∴能够通过上述公式将tan(α)求出,然后就是通过atan((tan(α)))将α求出
接着检查α是否符合条件就能够了。
/*
Author: 2486
Memory: 1616 KB Time: 0 MS
Language: C++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=acos(-1);
const double G=9.8;
int T;
double x,y,v;
int main() {
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf",&x,&y,&v);
double a=G*x*x,b=-2.0*v*v*x,c=2.0*v*v*y+G*x*x;
double posi=(-b+sqrt(b*b-4.0*a*c))/2.0/a;
double ne=(-b-sqrt(b*b-4.0*a*c))/2.0/a;
posi=atan(posi),ne=atan(ne);
if(posi>=0&&posi<=PI/2.0&&ne>=0&&ne<=PI/2.0) {
printf("%.6lf\n",posi>ne? ne:posi);
} else if(ne>=0&&ne<=PI/2.0) {
printf("%.6lf\n",ne);
} else if(posi>=0&&posi<=PI/2.0) {
printf("%.6lf\n",posi);
} else printf("-1\n");
}
return 0;
}
三分二分方法
/*
Author: 2486
Memory: 1628 KB Time: 0 MS
Language: C++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=acos(-1);
const double eps=1e-10;
int T;
double x,y,v;
double C(double m) {
double vx=v*cos(m),vy=v*sin(m);
return (vy*x)/vx-9.8*(x/vx*x/vx)/2.0;
}
bool B(double m) {
double vx=v*cos(m),vy=v*sin(m);
return (vy*x)/vx-9.8*(x/vx*x/vx)/2.0>=y;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf",&x,&y,&v);
double lb=0,ub=PI/2.0;
///////////////求出最大高度所相应的倾斜度////////////////
while(ub-lb>eps) {
double mid=(ub+lb)/2.0;
double mmid=(ub+mid)/2.0;
if(C(mid)>C(mmid)) {
ub=mmid;
} else lb=mid;
}
if(C(ub)<y) {
printf("-1\n");
continue;
}
///////////////////////////////
lb=0;
////////////////求出无限接近目标的倾斜度///////////////
while(ub-lb>eps) {
double mid=(ub+lb)/2.0;
if(B(mid)) {
ub=mid;
} else lb=mid;
}
///////////////////////////////
printf("%.6lf\n",ub);
}
return 0;
}
Toxophily-数论以及二分三分的更多相关文章
- 第二次组队赛 二分&三分全场
网址:CSUST 7月30日(二分和三分) 这次的比赛是二分&三分专题,说实话以前都没有接触过二分,就在比赛前听渊神略讲了下.......不过做着做着就对二分熟悉了,果然做题是学习的好方法啊~ ...
- HDU 2298 Toxophily 【二分+三分】
一个人站在(0,0)处射箭,箭的速度为v,问是否能够射到(x,y)处,并求最小角度. 首先需要判断在满足X=x的情况下最大高度hmax是否能够达到y,根据物理公式可得 h=vy*t-0.5*g*t*t ...
- CF 8D Two Friends 【二分+三分】
三个地点构成一个三角形. 判断一下两个人能否一起到shop然后回家,如果不能: 两个人一定在三角形内部某一点分开,假设沿着直线走,可以将问题简化. 三分从电影院出来时候的角度,在对应的直线上二分出一个 ...
- Codeforces Gym100543B 计算几何 凸包 线段树 二分/三分 卡常
原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543B.html 题目传送门 - CF-Gym100543B 题意 给定一个折线图,对于每一条 ...
- CodeForces - 1059D——二分/三分
题目 题目链接 简单的说,就是作一个圆包含所有的点且与x轴相切,求圆的最小半径 方法一 分析:求最小,对半径而言肯定满足单调性,很容易想到二分.我们二分半径,然后由于固定了与X轴相切,我们对于每一个点 ...
- uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...
- HDU2899Strange fuction(二分/三分)
传送门 题目大意:求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100):的最小值 题解:求个导,二分导函数零点,就是原函数最小值所在的 ...
- [CSP-S模拟测试]:柱状图(树状数组+二分+三分)
题目描述 $WTH$获得了一个柱状图,这个柱状图一共有$N$个柱子,最开始第$i$根柱子的高度为$x_i$,他现在要将这个柱状图排成一个屋顶的形状,屋顶的定义如下:$1.$屋顶存在一个最高的柱子,假设 ...
- 2020牛客寒假算法基础集训营5 B.牛牛战队的比赛地 (二分/三分)
https://ac.nowcoder.com/acm/contest/3006/B 三分做法 #include<bits/stdc++.h> #define inf 0x3f3f3f3f ...
随机推荐
- push和unshift方法
push和unushift都是向数组插入元素. push是向数组尾部插入元素. unshift是向数组头部插入元素. 共同点:都可以一次插入多个元素. arrayObject.push(newelem ...
- JDBC2.0操作:结果集,更新,插入,删除,批处理语句
JDBC对ResultSet的支持 JDBC最重要的概念是批处理,可以一次完成多个语句的执行. 可滚动的结果集. 如果想创建可滚动的结果集,则在创建PrepareStatement时候必须指定创建的类 ...
- classloader常见问题总结
h tp://yourenyouyu2008.iteye.com/blog/779707看到一些ClassNoFindException ,ClassCastException等异常首先应该想到是不是 ...
- php 删除文件夹下的所有文件
$patch = dirname(__FILE__).'/Cookie/';//获取文件目录 $files = scandir($patch); foreach ($files as $filenam ...
- 实现Windows Server 2003多用户远程登录(转载)
Windows Server 2003默认情况下允许远程终端连接的数量是2个用户,我们可以根据需要适当增加远程连接同时在线的用户数. 单击“开始→运行”,输入“gpedit.msc”打开组策略编辑器窗 ...
- linux下创建用户(转)
转自 http://www.cnblogs.com/ylan2009/articles/2321177.html Note: 1, Linux Shell 按Tab键不能补全 发现使用新增的用户登陆的 ...
- windows server 2003下搭建amp环境
参考: http://blog.csdn.net/binyao02123202/article/details/7578914 http://4359260.blog.51cto.com/434926 ...
- gcc 编译动态库和静态库
Linux C 编程入门之一:gcc 编译动态库和静态库 cheungmine 2012 参考: C程序编译过程浅析 http://blog.csdn.net/koudaidai/article/de ...
- PHP代码审计学习之命令执行漏洞挖掘及防御
[1]可能存在命令执行漏洞的函数: 00x1:常用的命令执行函数:exec.system.shell_exec.passthru 00x2:常用的函数处理函数:call_user_func.call_ ...
- (译)Getting Started——1.2.2 Desinging a User Interface(设计用户界面)
用户需要以最简单的方式与应用界面进行交互.应该从用户的角度出发设计页面,使得界面更高效.简捷和直接. storyboard以图形化的方式帮助你设计和实现界面.在设计和实现界面的过程中,你 ...