时间限制 1000 ms 内存限制 65536 KB

题目描述

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 (1≤T≤10)      , indicating the number of test cases.
    For each test case, the first line contains an integer N (1≤N≤10000), indicating the number of balloons.
    The second line contains N integers, the i-th integer indicates Hi (0≤Hi≤100000000)       , the height of the i-th balloon at 0second.
    The third line contains N integers, the i-th integer indicates Si (1≤Si≤10000)        , 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]<i,意味着在第i秒开枪击落它的时候,它已经早就飞过了当前二分的高度h,向上继续飞了,所以这样说吗高度不够,继续向高处二分,否则向低处二分。

#include<cstdio>
#include<cmath>
#include<algorithm>
#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<n;i++)scanf("%d",&hw[i]);for(i=0;i<n;i++)scanf("%d",&sw[i]);int up,down;int ans=MH;up=MH;down=0;int mid;while(down<=up){int sig=0;mid=(down+up)/2;for(i=0;i<n;i++){if(mid<hw[i]){sig=0;goto op;}else{tt[i]=(mid-hw[i])/sw[i];}}sort(tt,tt+n);for(i=0;i<n;i++){if(tt[i]<i){sig=0;goto op;}}sig=1;op:if(sig==1){ans=min(ans,mid);up=mid-1;}else{down=mid+1;}}printf("%d\n",ans);}return 0;
}

北邮OJ 1027. 16校赛-Archer in Archery相关推荐

  1. 北邮OJ 1022. 16校赛-Saber's Board

    时间限制 5000 ms 内存限制 65536 KB 题目描述 In a parallel universe, Saber has won the champion of every kind of ...

  2. 北邮OJ 1021. 16校赛-Stone Game

    时间限制 4000 ms 内存限制 65536 KB 题目描述 Alice and Bob are old friends in game theory. This afternoon they me ...

  3. 北邮OJ 1010. 16校赛-Binary Strings

    时间限制 5000 ms 内存限制 65536 KB 题目描述 One day, the teacher asked Weishen to judge whether a binary string ...

  4. 北邮OJ 1005. 16校赛-Hawei Learning C

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Hawei is learning C programming language recently, but he is so naiv ...

  5. 北邮OJ 981. 16校赛-Saber's Number Game

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Saber is fond of number games of various kinds, she particularly lik ...

  6. 北邮OJ 980. 16校赛-R_clover's Challenge

    时间限制 2000 ms 内存限制 65536 KB 题目描述 R_clover wants to challenge Mengmengda_wsw's math,so he give her a f ...

  7. 北邮OJ 884. 16校赛-Average Modulo

    时间限制 5000 ms 内存限制 65536 KB 题目描述 We define function g on an array as: g([a0,a1,⋯,an−1])=(Σn−1l=0al) m ...

  8. 北邮oj题库刷题计划(更新ing)

    北邮oj题库刷题计划(更新ing) 83. A + B Problem 84 Single Number 85. Three Points On A Line 120 日期 121 最值问题 122 ...

  9. 北邮OJ 141 虚数

    北邮OJ 虚数 #include <bits/stdc++.h> using namespace std; typedef struct fushu{int x; //实部 int y; ...

最新文章

  1. 【转】 LSD(Line Segment Detector) 直线段检测算法学习~
  2. web_find和web_reg_find的用法和区别
  3. [转]IaaS、PaaS、SaaS、CaaS、MaaS五者的区别
  4. 凝聚式层次聚类 java_凝聚法层次聚类之ward linkage method
  5. Struts2中Session的使用
  6. redis 分布式锁流程图
  7. Script To Monitor RDBMS Session UGA and PGA Current And Maximum Usage Over Time
  8. eval('{kkk:{}}')出错,eval('{}')与eval('var ss = {kkk:{}}')正常
  9. Vivado 2019.1下载与安装
  10. 车牌识别及提取系统MATLAB,车牌识别系统设计及MATLAB仿真
  11. jinjia2调用json文件注意事项
  12. 【Windows Tips】关闭 Windows Defender
  13. ROS创建Web代理(Web proxy)
  14. CommonAPI使用例子-HelloWorld
  15. 嵌入式软件工程师—成长笔记#03
  16. 【SQL】LeetCode-Trips and Users
  17. 图形图像学习随笔:计算机图形学的一些基本概念
  18. 医学图像分类_腾讯八篇论文入选顶级医学影像会议MICCAI ,涉及病理癌症图像分类等...
  19. 用计算机弹远走高飞谱,远走高飞计算器音谱 | 手游网游页游攻略大全
  20. 万能播放器KMPlayer

热门文章

  1. 直播 | 北京邮电大学助理教授王啸:网络嵌入的最新进展
  2. 漫谈概率 PCA 和变分自编码器
  3. 樊登高效休息法心得400字_真的,你应该早点知道这个高效学习方法
  4. python画一个点_pygame学习笔记(2):画点的三种方法和动画实例
  5. modis数据介绍_【更新90篇】地理数据科学技术文章合集,欢迎大家点赞、在看、转发三连!...
  6. oracle 安装及使用方法,Oracle安装及使用小结
  7. spring boot+shiro+vue前后端分离时,获取不到session
  8. LeetCode 32 最长有效括号
  9. Vue-CLI@4——html-webpack-plugin默认配置的获取与修改
  10. 播放[.m3u8]链接解决方案