北邮OJ 1027. 16校赛-Archer in Archery
時間限制?1000 ms?內(nèi)存限制?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既然最優(yōu)解是惟一的,那么也就是在某一時間點(diǎn)上射擊某個特定的氣球是必須的,才可以得到lowest score
那么在這個時間點(diǎn)射擊了氣球的時候,其它氣球的高度也就被確定下來了,因?yàn)槊總€氣球都有初始高度和上升速度,在某一時間確定了一個球的高度,那么其它氣球的高度也就可以被確定。
但是我們不能枚舉某個氣球在[0,N-1]秒內(nèi)所有的情況,這樣會超時,因?yàn)檫@樣就O(N^2)了。那么我們二分氣球的高度,只需要log2(MAXH),我們枚舉每一個高度,如果當(dāng)前高度比某個氣球的初始高度還低,那就向高處二分;如果沒前面的問題,那么我們求出每個氣球到達(dá)這個高度的飛行時間,并且從小到大排序,然后順次從i=0開始檢查每個氣球的飛行時間和i的關(guān)系,排序之后,i意味著,第i秒開槍擊落這個氣球,但如果t[i]<i,意味著在第i秒開槍擊落它的時候,它已經(jīng)早就飛過了當(dāng)前二分的高度h,向上繼續(xù)飛了,所以這樣說嗎高度不夠,繼續(xù)向高處二分,否則向低處二分。
#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; }
總結(jié)
以上是生活随笔為你收集整理的北邮OJ 1027. 16校赛-Archer in Archery的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北邮OJ 1022. 16校赛-Sabe
- 下一篇: 北邮OJ 2016网预 - Saber'