E. Cannon
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the Ox axis is directed rightwards in the city's direction, the Oy axis is directed upwards (to the sky). The cannon will make n more shots. The cannon balls' initial speeds are the same in all the shots and are equal to V, so that every shot is characterized by only one number alphai which represents the angle at which the cannon fires. Due to the cannon's technical peculiarities this angle does not exceed 45 angles (π / 4). We disregard the cannon sizes and consider the firing made from the point (0, 0).

The balls fly according to the known physical laws of a body thrown towards the horizon at an angle:

vx(t) = V·cos(alpha)vy(t) = V·sin(alpha)  –  g·tx(t) = V·cos(alphaty(t) = V·sin(alphat  –  g·t2 / 2

Think of the acceleration of gravity g as equal to 9.8.

Bertown defends m walls. The i-th wall is represented as a vertical segment (xi, 0) - (xi, yi). When a ball hits a wall, it gets stuck in it and doesn't fly on. If a ball doesn't hit any wall it falls on the ground (y = 0) and stops. If the ball exactly hits the point (xi, yi), it is considered stuck.

Your task is to find for each ball the coordinates of the point where it will be located in the end.

Input

The first line contains integers n and V (1 ≤ n ≤ 104, 1 ≤ V ≤ 1000) which represent the number of shots and the initial speed of every ball. The second line contains n space-separated real numbers alphai (0 < alphai < π / 4) which represent the angles in radians at which the cannon will fire. The third line contains integer m (1 ≤ m ≤ 105) which represents the number of walls. Then follow m lines, each containing two real numbers xi and yi (1 ≤ xi ≤ 1000, 0 ≤ yi ≤ 1000) which represent the wall’s coordinates. All the real numbers have no more than 4 decimal digits. The walls may partially overlap or even coincide.

Output

Print n lines containing two real numbers each — calculate for every ball the coordinates of its landing point. Your answer should have the relative or absolute error less than 10 - 4.

Examples
input

Copy
2 10
0.7853
0.3
3
5.0 5.0
4.0 2.4
6.0 1.9
output

Copy
5.000000000 2.549499369
4.000000000 0.378324889
input

Copy
2 10
0.7853
0.3
2
4.0 2.4
6.0 1.9
output

Copy
10.204081436 0.000000000
4.000000000 0.378324889 题意:

   有一门大炮,坐标在(0,0)(0,0),和mm堵墙,现在大炮要射nn发炮弹,每发炮弹的初始速度v是一样的,射击角度为α(0<α<π/4),假设射击后经过时间t,重力加速度g=9.8,则有:

   x​(t)=v∗cos(α)

   y​(t)=v∗sin(α)−g∗t

   x(t)=vx​(t)∗t

   y(t)=v∗sin(α)∗t−g∗t2/2

   给定m堵墙墙顶坐标(xi​,yi​),墙垂直于xx坐标轴,炮弹如果打到墙上,就会卡住;如果掉到地上,也不会再滚动。

   求这n发炮弹最终的位置

                                                      ----translate by 守望、copy from 洛谷

  题解:显然如果速度相同,角度在45度以内,那么角度越大的射的越高越远,所以如果矮的能越过的墙高的也能越过,把问题离线下来按照角度排序,模拟每个球会怎么走就可以了,显然每堵墙只会被访问一遍,均摊复杂度O(1),总复杂度O(n)

代码如下:

  

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; struct bomb
{
int id;
double a,ansx,ansy;
} b[]; struct wall
{
double x,y;
} w[]; int n,m;
double v; int cmp1(wall x,wall y)
{
if(x.x==y.x) return x.y<y.y;
return x.x<y.x;
} int cmp2(bomb x,bomb y)
{
return x.a<y.a;
} int cmp3(bomb x,bomb y)
{
return x.id<y.id;
} int main()
{
double g=9.8;
scanf("%d %lf",&n,&v);
for(int i=; i<=n; i++)
{
scanf("%lf",&b[i].a);
b[i].id=i;
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%lf%lf",&w[i].x,&w[i].y);
}
sort(w+,w+m+,cmp1);
sort(b+,b+n+,cmp2);
int r=;
for(;; r++)
{
if(r>m)
{
r=m+;
break;
}
double t=w[r].x/(cos(b[].a)*v);
if(v*sin(b[].a)*t-g*t*t/<=w[r].y)
{
break;
}
}
for(int i=; i<=n; i++)
{
while()
{
if(r>m)
{
r=m+;
break;
}
double t=w[r].x/(cos(b[i].a)*v);
if(v*sin(b[i].a)*t-g*t*t/>=w[r].y) r++;
else break;
}
double t=w[r].x/(cos(b[i].a)*v);
if(r<=m)
{
b[i].ansy=(v*sin(b[i].a)*t)-(g*t*t/);
b[i].ansx=w[r].x;
}
else
{
b[i].ansy=;
b[i].ansx=(v*sin(b[i].a)/g)*v*cos(b[i].a)*;
}
}
sort(b+,b+n+,cmp3);
for(int i=; i<=n; i++)
{
if(b[i].ansy<)
{
b[i].ansy=;
b[i].ansx=(v*sin(b[i].a)/g)*v*cos(b[i].a)*;
}
printf("%.9lf %.9lf\n",b[i].ansx,b[i].ansy);
}
}

CodeForces 47E. Cannon(离线暴力+数学)的更多相关文章

  1. Codeforces Beta Round #4 (Div. 2 Only) A. Watermelon【暴力/数学/只有偶数才能分解为两个偶数】

    time limit per test 1 second memory limit per test 64 megabytes input standard input output standard ...

  2. Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力

    D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...

  3. Codeforces 1087B Div Times Mod(数学+暴力)

    题意: 求(x div k) * (x mod k) = n的最小解x,保证有解 1<=n<=1e6, k<=1000,1s 思路: 注意到k的范围是1e3, 1<=x mod ...

  4. codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)

    题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...

  5. codeforces 897A Scarborough Fair 暴力签到

    codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...

  6. Codeforces 789A Anastasia and pebbles(数学,思维题)

    A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  7. B. Apple Tree 暴力 + 数学

    http://codeforces.com/problemset/problem/348/B 注意到如果顶点的数值确定了,那么它分下去的个数也就确定了,那么可以暴力枚举顶点的数值. 顶点的数值是和LC ...

  8. Codeforces Little Dima and Equation 数学题解

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. Codeforces A. Playlist(暴力剪枝)

    题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. App切图命名规范

    转自:http://www.uisdc.com/slice-rename-in-ui-design(略有修改) 关于切图命名的规范,我个人觉得关键是在于团队能够有一个统一的规则,所有成员严格遵守并且和 ...

  2. 初始mysql语句

    操作文件夹(库) 增 : create database db1 charset utf8; 查 : #查看当前创建的数据库 show create database db1; #查看所有的数据库 s ...

  3. 关于微软的.NET版本系列

    .net的不同版本的区分,感觉十分坑,搞开发的不能还去研究他们的版本含义或差异吧!下面为整理的一些相关内容: 一..NET的那些版本 .net framework 版本是可以向后兼容的,安装高版本的可 ...

  4. Windows下安装kibana

    1. 下载ElasticSearch https://www.elastic.co/downloads/kibana https://www.elastic.co/downloads/past-rel ...

  5. 关于BigDecimal类型在jsp页面中进行除法运算问题

    出自:http://blog.csdn.net/u011910290/article/details/52935337 问题描述: 在项目编写过程中,发现BigDecimal在jsp中进行除法运算时, ...

  6. Subversion Self Signed Certificates

    When connecting to Subversion repositories using SSL connections the SVN client checks the server ce ...

  7. 关于data-属性

    关于data-属性 现有需求如下,也就是类似做一个tab页的切换如下图: 因为这里要记录一下jquery里的“data-属性”的用法,所以忽略类似的组件. 往HTML标签上添加任意以 "da ...

  8. react native android 真机调试

    http://localhost:8081/index.android.bundle?platform=android 晕死,设备掉线了 C:\Users\ZHONGZHENHUA\.android\ ...

  9. python用sqlite3模块操作sqlite数据库-乾颐堂

    SQLite是一个包含在C库中的轻量级数据库.它并不需要独立的维护进程,并且允许使用非标准变体(nonstandard variant)的SQL查询语句来访问数据库. 一些应用可是使用SQLite保存 ...

  10. JMS 之 Active MQ 的spring整合

    一.与spring整合实现ptp的同步接收消息 pom.xml: <!-- https://mvnrepository.com/artifact/org.springframework/spri ...