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. [Cpp primer] Namespace using Declarations

    If we want to use cin in the standard library, we need to std::cin To simplify this work, we can do ...

  2. Java-从堆栈常量池解析equals()与==

    一.基本概念 ①JAVA中的基本数据类型(简单类型,内置类型): 字节型(byte),短整型(short),整型(int),长整型(long),字符型(char),浮点型(float),双精度型(do ...

  3. 呕心沥血Android studio使用JNI实例

    发现网上很多JNI的使用教程,也很详细,不过有的地方有些缺漏,导致很多小问题难以解决的,今天就来总结一下. 准备工作:下载NDK. 简单的说,要用到C/C++,就要用NDK.直接百度搜索然后去官网下载 ...

  4. 5、数据类型三:hash

    Hash数据类型使用很普遍,它同样是key-value的方式来组织的,只是其value又包含多个field-fieldValue对.想要获取某个fieldValue,可以通过key-field联合来定 ...

  5. C#中 标识符“XXX”不符合 CLS

    标识符“XXX”不符合 CLS,意思是只要是不与外面有接口,比如在私有函数中操作,可是使用一些不符合cls的类型,但是如果是公共的,就必须要符合这个规范. 解决方法是,将这个类中的这些public类型 ...

  6. 页面生成柱状图 --- D3.js

    转载自:https://www.cnblogs.com/fastmover/p/7779660.html D3.js从入门到"放弃"指南 前言 近期略有点诸事不顺,趁略有闲余之时, ...

  7. shell编程——变量子串的常用操作

    ${#字符串} 返回字符串的长度 [root@localhost ~]# a=length [root@localhost ~]# echo ${#a} 6 ${字符串:位置x} 从位置x开始往后截取 ...

  8. C#中使用OracleTransaction

    1. OracleTransaction类的概述(from msdn )        应用程序通过针对OracleConnection对象调用 BeginTransaction 来创建OracleT ...

  9. 解决SharePoint下载文件时自动修改扩展名的问题

    今天,有人告诉了我一个有趣的问题.当用户将一个扩展名为.ai的文件(Adobe illustrator格式的文件)上载到SharePoint 2013文档库中之后,点击它下载时,下载提示栏所显示的文件 ...

  10. Python_12-线程编程

    1.1    Python中的线程使用1.1.1 函数式1.2    创建threading.Thread的子类来包装一个线程对象1.2.1 threading.Thread类的使用1.3    线程 ...