hiho 175 周 贪心 (北美startup的面试题)
来源:互联网 发布:windows 10 无法开机 编辑:程序博客网 时间:2024/05/17 08:04
#1340 : Robots Crossing River
- 样例输入
40 4 4
- 样例输出
24
描述
Three kinds of robots want to move from Location A to Location B and then from Location B to Location C by boat.
The only one boat between A and B and only one between B and C. Moving from A to B (and vise versa) takes 2 hours with robots on the boat. Moving from B to C (and vice versa) takes 4 hours. Without robots on the boat the time can be reduced by half. The boat between A and B starts at time 0 moving from A to B. And the other boat starts 2 hours later moving from B to C.
You may assume that embarking and disembarking takes no time for robots.
There are some limits:
1. Each boat can take 20 robots at most.
2. On each boat if there are more than 15 robots, no single kind of robots can exceed 50% of the total amount of robots on that boat.
3. At most 35 robots are allowed to be stranded at B. If a robot goes on his journey to C as soon as he arrives at B he is not considered stranded at B.
Given the number of three kinds robots what is the minimum hours to take them from A to C?
输入
Three integers X, Y and Z denoting the number of the three kinds of robots. (0 ≤X, Y and Z ≤ 1000)
输出
The minimum hours.
官方题解:
对于 x <=y+z 的理解,可以用三角形来理解
若 x>y+z 的时候,每次运20,会导致最后 x 无法运完
例如
x ----------------------
y ------- z -------
按照这种思路去想就行了
然后发现一个坑点:
最后非 x 类小于8的时候其实我们可以运15个一船
#include<math.h>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int cmp(const int &x,const int &y){ return x>=y?1:0;}int main(){ int a[10]; //freopen("in.txt","r",stdin); while(scanf("%d%d%d",&a[1],&a[2],&a[3])!=EOF) { sort(a+1,a+4,cmp); int ans=0; if(a[1]<=(a[2]+a[3])) ans=ceil((a[1]+a[2]+a[3])/20.0); else{ ans+=(a[2]+a[3])/10; a[1]-=ans*10; int x=(a[2]+a[3])%10; if(x&&x<8) a[1]-=(15-x),ans++; else if(x) a[1]-=x,ans++; ans+=ceil(a[1]/15.0); } printf("%d\n",ans*6); } return 0;}
- hiho 175 周 贪心 (北美startup的面试题)
- hiho模拟面试题2 补提交卡 (贪心,枚举)
- 北美微软面试题---数组问题
- hiho #1051 : 补提交卡 (hiho模拟面试题2 - google在线技术笔试模拟 贪心+枚举)
- hiho一下第65周微软面试题《Highway》题目分析
- 手机的九宫格图案解锁总共能绘出多少种图案?(hiho模拟面试题2 - google在线技术笔试模拟)
- hiho 1051 : 补提交卡(贪心 )
- hiho#1054 : 滑动解锁 (hiho模拟面试题2 - google在线技术笔试模拟)
- 【面试题】 单链表的热点面试题(1 )
- hiho一下 第110周 floyd + 贪心 + 倍增
- hiho 1165 益智游戏(因子个数+贪心)
- Nokia的北美困局
- 北美第二周
- hiho一下 第175周
- 2014 hiho模拟面试题1 - google在线技术笔试模拟 矩形判断
- hiho 博弈——01(hiho 44周)
- hiho一下 第四十九周(欧拉路的判定)49
- 北美IT公司面经礼包
- java中如何输入char类型
- C++:汉诺塔问题
- 自学网络结构(二):Learning Transferable Architectures for Scalable Image Recognition
- Nvidia Jetson TX2 运行Faster RCNN物体检测demo
- TCP状态机
- hiho 175 周 贪心 (北美startup的面试题)
- 数据成员绑定
- C语言:角股定理
- 关于JS函数的一些基本理解
- HDU 6242/2017CCPC哈尔滨 Geometry Problem 【随机化+计算几何】
- 用图说什么是爬虫
- C++:三羊献瑞
- 类方法和实例方法
- centos7安装mysql