题目描述

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()                                //读入优化
 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

转载于:https://www.cnblogs.com/SoulSecret/p/9562360.html

[二分]Kayaking Trip相关推荐

  1. Nordic Collegiate Programming Contest 2017 题解

    前几天打了一场外国人的比赛,感觉那边的题目质量还是很好的,区分度很鲜明,题目没有国内的难,坑点比较少,比较注重思维,基础算法. B题: Best Relay Team Picture by Ferna ...

  2. nssl1155-遨游【二分答案,SPFA】

    正题 题目大意 有若干个省,每个省有些城市,每个省有优惠Xi%X_i\%Xi​%,若在i省内的道路就优惠Xi%X_i\%Xi​%,若在i到j省的道路就优惠(Xi%+Yi%)2\frac {(X_i\% ...

  3. UVALive 4223 Trucking 二分+spfa

    Trucking 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...

  4. Codeforces Round #499 (Div. 2) 1011 C. Fly 二分

    C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  5. LeetCode 二分查找

    文章目录 [0378. 有序矩阵中第K小的元素 [Medium] [Kth Smallest Element in a Sorted Matrix]](https://leetcode.com/pro ...

  6. 技巧专题1(二分、三分、位运算)

    二分 二分答案一般有以下的一些特征: A. 候选答案在区间[min,max]上按照某种属性有序,一般枚举复杂度较高. B. 容易判断某个点是否为可行 最大值最小. 判断一个东西是否在一个有序集合中出现 ...

  7. 算法图解/二分查找/简单查找/选择排序/递归算法/快速排序算法/

    大 O 表示法 大 O 表示法在讨论运行时间时,log 指的都是 log2 大 O 表示法指出了算法有多快,让你能够比较操作数,它指出了算法运行时间的增速,而并非以秒为单位的速度. 大 O 表示法指出 ...

  8. 分治算法的设计思想(二分检索、二分归并排序)

    分治策略思想: 将原问题划分或者归结为规模较小的子问题. 递归或迭代求解每一个问题. 将子问题的解综合得到原问题的解. 性质: 子问题与原问题具有相同的性质. 子问题的求解彼此独立. 划分时子问题的规 ...

  9. LeetCode简单题之二分查找

    题目 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1. 示例 1: 输入: n ...

  10. 二分查找模板全面总结

    二分查找 二分法的引入 情形1 1.X的平方根 2.搜索旋转排序数组 情形2 1.第一个错误的版本 2.寻找峰值 3.寻找旋转排序数组中的最小值 情形3 在排序数组中查找第一个和最后一个位置 当遇到查 ...

最新文章

  1. 【构造】CF12E Start of the season(神奇的构造)难度⭐⭐⭐
  2. jQuery-this与$(this)的区别
  3. Nginx如何实现支持HTTPS协议详细说明
  4. 阿里巴巴开源项目 Druid 负责人温少访谈
  5. 英语对计算机人才的重要性,英语对计算机专业的重要性及如何提高英语水平
  6. 大学生英语fif测试系统_英语听力解题技巧
  7. Web Hacking 101 中文版 十七、服务端请求伪造
  8. javascriptjquery 判断滚动到页面底部
  9. Super VLAN
  10. 向java全台推送数据等
  11. 3DMAX最强搭配神器,一键清理病毒,让你学习工作更流畅!
  12. 经典贪心算法问题:会议安排
  13. 这样配置win10亲测不错
  14. 用360安全卫士检查计算机中是否有木马,你的电脑真的做好防护了吗?使用360安全卫士木马查杀一键扫描就知道...
  15. 【树】B056_LQ_三角形面积 阅兵方阵 版本分支(递归预处理)
  16. 两种有效提高win10电脑开机速度的方法
  17. 实时音频编解码之四 LPC和LSF
  18. 机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理、源码解析及测试...
  19. 债券收益率建模(时间序列建模)时间序列相似度度量
  20. 利用百度地图Android sdk高仿微信发送位置功能

热门文章

  1. u盘推荐知乎_市面上的U盘怎么选择?U盘那个牌子好?
  2. 前端三件套之CSS(二)
  3. 模板库(七) - 字符串算法
  4. Oracle:ORA-00054 资源正忙 -- 锁表的解决方法
  5. 广东电信最新DNS更新了
  6. 双机热备 ip地址_双机热备软件哪个好?双机热备软件推荐
  7. Unity Singleton 单例类
  8. outlook邮件通过python发送_怎么发送邮箱-python调用outlook发送邮件的超详细操作步骤...
  9. 计算机arp 各命令,ARP命令参数详解
  10. hadoop reducer不执行问题及解决