Codeforces Gym 100531J Joy of Flight 变换坐标系
2016-01-18 19:10
267 查看
Joy of Flight
题目连接:
http://codeforces.com/gym/100531/attachmentsDescription
Jacob likes to play with his radio-controlled aircraft. The weather today is pretty windy and Jacob hasto plan flight carefully. He has a weather forecast — the speed and direction of the wind for every second
of the planned flight.
The plane may have airspeed up to vmax units per second in any direction. The wind blows away plane
in the following way: if airspeed speed of the plane is (vx, vy) and the wind speed is (wx, wy), the plane
moves by (vx + wx, vw + wy) each second.
Jacob has a fuel for exactly k seconds, and he wants to learn, whether the plane is able to fly from start
to finish in this time. If it is possible he needs to know the flight plan: the position of the plane after
every second of flight.
Input
The first line of the input file contains four integers Sx, Sy, Fx, Fy — coordinates of start and finish(−10 000 ≤ Sx, Sy, Fx, Fy ≤ 10 000).
The second line contains three integers n, k and vmax — the number of wind condition changes, duration
of Jacob’s flight in seconds and maximum aircraft speed (1 ≤ n, k, vmax ≤ 10 000).
The following n lines contain the wind conditions description. The i-th of these lines contains integers
ti
Output
The first line must contain “Yes” if Jacob’s plane is able to fly from start to finish in k seconds, and “No”otherwise.
If it can to do that, the following k lines must contain the flight plan. The i-th of these lines must contain
two floating point numbers x and y — the coordinates of the position (Pi) of the plane after i-th second
of the flight.
The plan is correct if for every 1 ≤ i ≤ k it is possible to fly in one second from Pi−1 to some point
Qi
, such that distance between Qi and Pi doesn’t exceed 10−5
, where P0 = S. Moreover the distance
between Pk and F should not exceed 10−5 as well.
Sample Input
1 1 7 42 3 10
0 1 2
2 2 0
Sample Output
Yes3 2.5
5 2.5
7 4
Hint
题意
给你一个起点和终点,然后会有风,问你能否在k秒内到达终点如果可以的话,就输出每一秒之后,你在哪儿
题解:
和CF的某道题一样的,把坐标系变换一下,把风直接的按在终点倒着跑然后直接看一下时间是否小于等于k就好了
如果小于的话,就直接跑平均速度就好了
代码
#include<bits/stdc++.h> using namespace std; double sx,sy,fx,fy; int n,k,t[20005]; double v,wx[20005],wy[20005]; double vx,vy; int tot = 0; double winx=0,winy=0; int check(int mid) { tot = 0,winx = winy = 0; double ex = fx,ey = fy; for(int i=0;i<mid;i++) { if(tot<n&&t[tot]==i) winx=wx[tot],winy=wy[tot],tot++; ex-=winx,ey-=winy; } double dis = sqrt((ex-sx)*(ex-sx)+(ey-sy)*(ey-sy)); if(dis/v>mid)return 0; return 1; } int main() { freopen("joy.in","r",stdin); freopen("joy.out","w",stdout); cin>>sx>>sy>>fx>>fy; cin>>n>>k>>v; for(int i=0;i<n;i++) cin>>t[i]>>wx[i]>>wy[i]; int L = 0; for(;L<=k+5;L++) if(check(L)) break; if(L>k)return puts("No"); double ex = fx,ey = fy; tot = winx = winy = 0; for(int i=0;i<L;i++) { if(tot<n&&t[tot]==i) winx=wx[tot],winy=wy[tot],tot++; fx-=winx,fy-=winy; } double l = fx - sx; double h = fy - sy; double dis = sqrt(l*l+h*h); double vx = v * l / dis; double vy = v * h / dis; tot = winx = winy = 0; puts("Yes"); if(L==0)L++; for(int i=0;i<L-1;i++) { if(tot<n&&t[tot]==i) winx=wx[tot],winy=wy[tot],tot++; sx += vx + winx; sy += vy + winy; printf("%.6f %.6f\n",sx,sy); } for(int i=L;i<=k;i++) printf("%.6f %.6f\n",ex,ey); }
相关文章推荐
- 0815-超级猜图(笔记)
- Oracle第一天之Oracle介绍
- Android Studio下载,SDK下载以及代理
- yii随笔(三) 开启友好路径
- 列表页的动态条件搜索
- Struts1的Action继承不同的父类有不同的作用
- PAT 1006
- Play FrameWork JSON操作小结
- 如何使用数组参数
- mysql查询当前日期的前一个月内的数据
- jd-gui报错INTERNAL ERROR 解决办法
- 关于robot的一些知识
- highcharts 阶梯图表并填充颜色(自己认为:直角折线图表)
- R语言包在linux上的安装、卸载
- 理解Objective-C Runtime
- python学习笔记-Day1
- 【OSG学习笔记之一:】OSG+VS2010+win7 64位环境搭建
- lsof
- 大型网站提速关键技术(页面静态化,memcached,MySql优化)(三)
- hdu 1159 Common Subsequence 最大公共子串