北邮OJ 1027. 16校赛-Archer in Archery

题目描述

    Archer(Emiya), also known as the red A, is famous for his talented skill of never missing a shot. Today Archer takes part in a rather different Archery competition. Each contestant will have to shoot down all N balloons numbered from 1 to N. The height of the i-th balloon at 0 second is Hi meters above the ground, and the ballon rises Si meters per second. The final score of the contestant is the highest height of the ballons when they are shot down. The one with the least score at last will win the champion! Although Archer will never miss, the rule restricts that he can only shoot one arrow at the beginning of one second, and shoot down only one target. Dedicated to win the champion, Archer wants you to calculate the lowest score he can get. You may assume the time for the arrow to shoot down a ballon won't cost any time.

 

输入格式

    The input starts with an integer T (1T10)      , indicating the number of test cases.
    For each test case, the first line contains an integer N (1N10000), indicating the number of balloons.
    The second line contains N integers, the i-th integer indicates Hi (0Hi100000000)       , the height of the i-th balloon at 0second.
    The third line contains N integers, the i-th integer indicates Si (1Si10000)        , the rising speed of the i-th balloon (meters per second).

输出格式

    For each test case, output one line containing an integer, indicating the lowest score Archer can get.

输入样例

2
1
10
10
2
10 1
1 5

输出样例

10
10
最大高度MAXH=N*Si+Hi=10000*10000+100000000=200000000

既然最优解是惟一的,那么也就是在某一时间点上射击某个特定的气球是必须的,才可以得到lowest score

那么在这个时间点射击了气球的时候,其它气球的高度也就被确定下来了,因为每个气球都有初始高度和上升速度,在某一时间确定了一个球的高度,那么其它气球的高度也就可以被确定。

但是我们不能枚举某个气球在[0,N-1]秒内所有的情况,这样会超时,因为这样就O(N^2)了。那么我们二分气球的高度,只需要log2(MAXH),我们枚举每一个高度,如果当前高度比某个气球的初始高度还低,那就向高处二分;如果没前面的问题,那么我们求出每个气球到达这个高度的飞行时间,并且从小到大排序,然后顺次从i=0开始检查每个气球的飞行时间和i的关系,排序之后,i意味着,第i秒开枪击落这个气球,但如果t[i]

#include
#include
#include
#define N 10050
#define MH 200000000
using namespace std;
int hw[N];
int sw[N];
int tt[N];
int main(){
    int t,n,i,m,k;
    for(scanf("%d",&t);t--;){
        scanf("%d",&n);
        for(i=0;i







你可能感兴趣的:(BOJ题解,枚举,北邮,2016ACM校赛,ACM)