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. mysql数据安全一之数据恢复案例

    mysql数据安全一之数据恢复案例 --chenjianwen 应用场景:适宜开启binlog 日志功能,定时备份并使用--master-data参数备份,在某个时间点丢失数据,用于数据恢复 开篇总结 ...

  2. springMVC 踩过的坑 - 记录

    1. 后台持久层Spring Jpa(即hibernate), 前台angularJS(angularJS只接受json串), 在后台使用DTO层对象代替domain(entity)与前台交互时, 传 ...

  3. 用Jmeter制造软件测试数据

    在测试过程难免会遇到一些需要大量测试数据的情况,如果数据没有太多的需求,或者需求本身比较简单,这时候我们可以用Jmeter参数化来实现(建议用badboy录制) 首先,我们可以通过badboy来录制实 ...

  4. "网页安全政策"(Content Security Policy,缩写 CSP)的来历

    作者:阿里聚安全链接:https://www.zhihu.com/question/21979782/answer/122682029来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  5. Django-组件--用户认证Auth(auth_user增加字段)

    引入: from django.db import models from django.contrib.auth.models import AbstractBaseUser 源码 : from d ...

  6. MySQL系统时间函数NOW(),CURRENT_TIMESTAMP(),SYSDATE()的区别

    CURRENT_TIMESTAMP是NOW的同义词,也就是说两者是相同的. SYSDATE函数返回的是执行到当前函数时的时间,而NOW返回的是执行SQL语句时的时间. 测试语句: SELECT NOW ...

  7. 【303】C# 复制窗体 & 修改名称

    参考:C#复制粘贴窗体 参考:VS修改项目解决方案名称 一.复制窗体 在“解决方案资源管理器”(以下简称:管理器)中选择要复制的窗体,比如要复制Form2,则在Form2.cs上右单击,选择复制. 在 ...

  8. nodejs中yield的用法?

    nodejs中yield的用法? https://www.zhihu.com/question/32752866?sort=created

  9. DOM0级与DOM2级

    定义: 0级DOM 分为2个:一是在标签内写onclick事件  二是在JS写onlicke=function(){}函数 1) <input id="myButton" t ...

  10. [C++] Variable/Hex conversion

    程序编译链接原理预处理:.c -> .i gcc -E hello.c -o hello.i 编译:.i / .c -> .sgcc -S hello.i -o hello.s 汇编:.s ...