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. Linux系统级别能够打开的文件句柄的数file-max命令

    简单的说, max-file表示系统级别的能够打开的文件句柄的数量, 而ulimit -n控制进程级别能够打开的文件句柄的数量. man 5 proc, 找到file-max的解释:file-max中 ...

  2. 13.solr学习速成之IK分词器

    IKAnalyzer简介 IKAnalyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包. IKAnalyzer特性 a. 算法采用“正向迭代最细粒度切分算法”,支持细粒度和最大词长两 ...

  3. django之设置缓存

    缓存 一句话总结:缓存可以对view.模板.数据进行缓存可以设置缓存在不同的地方(本地内存.redis.系统文档)可以为服务器节省性能.减少用户等待时间. 对于中等流量的网站来说,尽可能地减少开销是必 ...

  4. linux进程通信:消息队列

    消息队列可以实现两个没有关系的进程之间的通信. 创建了一个消息队列后,进程可以往里面放消息,也可以取消息.因为这个消息队列是有名字的,所以就算是两个没有关系的进程,也能通信. 而且人性化的一点是,可以 ...

  5. 【读书笔记】 DevOps实践 - 驭DevOps之力强化技术栈并优化IT运行

    读书小结 DevOps实践 - 驭DevOps之力强化技术栈并优化IT运行 这本书共200页,读完大概三天:(我指的不是fulltime的一天,而是工作时间以外的一天) 本书是参加16年QConf开发 ...

  6. 更改AD域安全策略-密码必须符合复杂性要求

    在域环境中,修改域用户密码时,会提示不符合密码策略, 更改"本地安全策略"是不会对域产生任何的作用的. 上图中可以看,这里按钮都是灰色的! 下面这个步骤教你如何找到"域安 ...

  7. Python基础学习九 单元测试

    import unittest import HTMLTestRunner #产生测试报告 from BeautifulReport import BeautifulReport def calc(x ...

  8. CodeFirst(反射+特性)

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...

  9. keepalived和zookeeper对比

    https://blog.csdn.net/vtopqx/article/details/79066703keepalived与zookeeper都可以用来实现高可用,高可用一般跟负载均衡会一起考虑, ...

  10. Gouraud Shading

    [Gouraud Shading] Gouraud Shading (高洛德着色/高氏着色) 这种着色的效果要好得多,也是在游戏中使用最广泛的一种着色方式.它可对3D模型各顶点的颜色进行平滑.融合处理 ...