日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/9/30 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 北邮OJ 1027. 16校赛-Archer in Archery 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間限制?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?(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]<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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。