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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

[二分]Kayaking Trip

發(fā)布時(shí)間:2023/12/13 综合教程 32 生活家
生活随笔 收集整理的這篇文章主要介紹了 [二分]Kayaking Trip 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目描述

You are leading a kayaking trip with a mixed group of participants in the Stockholm archipelago, but as you are about to begin your final stretch back to the mainland you notice a storm on the horizon. You had better paddle as fast as you can to make sure you do not get trapped on one of the islands. Of course, you cannot leave anyone behind, so your speed will be determined by the slowest kayak.
Time to start thinking; How should you distribute the participants among the kayaks to maximize your chance of reaching the mainland safely?
The kayaks are of different types and have different amounts of packing, so some are more easily paddled than others. This is captured by a speed factor c that you have already figured out for each kayak. The final speed v of a kayak, however, is also determined by the strengths s1 and s2 of the two people in the kayak, by the relation v = c(s1 + s2 ). In your group you have some beginners with a kayaking strength of sb , a number of normal participants with strength s n and some quite experienced strong kayakers with strength se .

輸入

The first line of input contains three non-negative integers b, n, and e, denoting the number of beginners, normal participants, and experienced kayakers, respectively. The total number of participants, b + n + e, will be even, at least 2, and no more than 100 000. This is followed by a line with three integers sb , sn , and se , giving the strengths of the corresponding participants (1 ≤ sb < sn < se ≤ 1 000). The third and final line contains m = (b+n+e)/2 integers c1 , . . . , cm(1 ≤ ci ≤ 100 000 for each i), each giving the speed factor of one kayak.

輸出

Output a single integer, the maximum speed that the slowest kayak can get by distributing the participants two in each kayak.

樣例輸入

3 1 0
40 60 90
18 20

樣例輸出

1600

思路:

  最大化最小值就是典型的二分特征嘛,二分嘍

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const int maxn = 1e5+50;
  4 const int INF = 0x7f7f7f7f;
  5 const double eps = 1e-8;
  6 struct node
  7 {
  8     int num_a;
  9     int num_b;
 10     int num_c;
 11     int need;
 12 };
 13 node pp[maxn];
 14 int x,y,z,stra,strb,strc,tot,all;
 15 int tx,ty,tz;
 16 int cap[maxn];
 17 inline int read()                                //讀入優(yōu)化
 18 {
 19     int x=0,f=1;
 20     char c=getchar();
 21     while (!isdigit(c))
 22         f=c=='-'?-1:1,c=getchar();
 23     while (isdigit(c))
 24         x=(x<<1)+(x<<3)+(c^48),c=getchar();
 25     return x*f;
 26 }
 27 void comb()
 28 {
 29     all=0;
 30     if(tx>=2)
 31     {
 32         pp[all].num_a=2;
 33         pp[all].num_b=0;
 34         pp[all].num_c=0;
 35         pp[all++].need=stra*2;
 36     }
 37     if(ty>=2)
 38     {
 39         pp[all].num_a=0;
 40         pp[all].num_b=2;
 41         pp[all].num_c=0;
 42         pp[all++].need=strb*2;
 43     }
 44     if(tz>=2)
 45     {
 46         pp[all].num_a=0;
 47         pp[all].num_b=0;
 48         pp[all].num_c=2;
 49         pp[all++].need=strc*2;
 50     }
 51     if(tx&&ty)
 52     {
 53         pp[all].num_a=1;
 54         pp[all].num_b=1;
 55         pp[all].num_c=0;
 56         pp[all++].need=stra+strb;
 57     }
 58     if(tz&&ty)
 59     {
 60         pp[all].num_a=0;
 61         pp[all].num_b=1;
 62         pp[all].num_c=1;
 63         pp[all++].need=strc+strb;
 64     }
 65     if(tz&&tx)
 66     {
 67         pp[all].num_a=1;
 68         pp[all].num_b=0;
 69         pp[all].num_c=1;
 70         pp[all++].need=strc+stra;
 71     }
 72 }
 73 bool cmp2(node a,node b)
 74 {
 75     return a.need<b.need;
 76 }
 77 bool judge(int v)
 78 {
 79     tx=x,ty=y,tz=z;
 80     for(int i=1; i<=tot; i++)
 81     {
 82         double nedd=v*1.0/cap[i];
 83         comb();
 84         sort(pp,pp+all,cmp2);
 85         bool flag=false;
 86         for(int i=0; i<all; i++)
 87         {
 88             if(nedd-1.0*pp[i].need<=eps)
 89             {
 90                 tx-=pp[i].num_a;
 91                 ty-=pp[i].num_b;
 92                 tz-=pp[i].num_c;
 93                 flag=true;
 94                 break;
 95             }
 96         }
 97         if(flag==false)
 98             return false;
 99     }
100     return true;
101 }
102 void div()
103 {
104     int l=1,r=INF;
105     int mid,ans;
106     while(r-l>1)
107     {
108         mid=(l+r)/2;
109         if(judge(mid))
110         {
111             l=mid;
112         }
113         else
114         {
115             r=mid;
116         }
117     }
118     cout << l<< endl;
119 }
120 int main()
121 {
122     x=read(),y=read(),z=read();
123     stra=read(),strb=read(),strc=read();
124     tot=(x+y+z)/2;
125     for(int i=1; i<=tot; i++)
126     {
127         cap[i]=read();
128     }
129     div();
130     return 0;
131 }

View Code

總結(jié)

以上是生活随笔為你收集整理的[二分]Kayaking Trip的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。