734C Anton and Making Potions
来源:互联网 发布:云计算培训机构 编辑:程序博客网 时间:2024/05/23 23:08
题目链接:
http://codeforces.com/problemset/problem/734/C
题解:
题目大意:
一个人升级需要n瓶药,这个人会两种魔法,第一种魔法可以缩减炼药的时间,另一种可以瞬间完成一些药。一瓶药在没有释放任何魔法的情况下,炼制的时间为x,并且,这个人所拥有的法力值为s,但是一个人最多每种魔法使用一次(注意不是每个),问你炼制这些药的最小的时间是多少。
这道题的数据的范围比较大,常规的暴力一定会超时,因此,这里很容易想到需要使用二分的方法。主要的问题是怎么来二分。我们可以这么想,我们对于第一种魔法的选择进行枚举,在魔力满足的条件下在尽可能的选择第二种。最后,将再对只取第二种的的贪心情况进行比较就可以了。
这里的二分,我是直接用stl里面的upper_bound,(一开始队友把lower_bound和upper_bound给记错了,下次还是要自己记住。)
upper_bound返回的是大于等于,lower_bound返回的是大于。
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define met(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3fconst int maxn = 2e5+10;typedef long long ll;ll num1[maxn],num2[maxn],num3[maxn],num4[maxn];int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); int x,s; scanf("%d%d",&x,&s); for(int i=1;i<=m;i++) scanf("%I64d",&num1[i]); for(int i=1;i<=m;i++) scanf("%I64d",&num2[i]); for(int i=1;i<=k;i++) scanf("%I64d",&num3[i]); for(int i=1;i<=k;i++) scanf("%I64d",&num4[i]); ll ans=(n-num3[upper_bound(num4+1,num4+1+k,s)-num4-1])*x; for(int i=1;i<=m;i++) { if(num2[i]<=s) ans=min(ans,(n-num3[upper_bound(num4+1,num4+1+k,s-num2[i])-num4-1])*num1[i]); } printf("%I64d\n",ans);}
友情提醒:c++11不支持%lld的输入。
0 0
- codeforces 734C Anton and Making Potions
- Codeforces 734C. Anton and Making Potions
- CodeForces 734C - Anton and Making Potions
- CodeForce-734C Anton and Making Potions
- 734C Anton and Making Potions
- 【13.77%】【codeforces 734C】Anton and Making Potions
- Codeforces 734C Anton and Making Potions(二分)
- Codeforce 734C Anton and Making Potions 枚举+二分
- CodeForces 734C Anton and Making Potions 【二分】【贪心】
- 【CodeForce 734C 】Anton and Making Potions (枚举+二分)
- Codeforces-734C-Anton and Making Potions(枚举+二分)
- 【Codeforces 734 C Anton and Making Potions 】+ 思维
- codeforces 734 C. Anton and Making Potions (二分 STL)
- CodeForces 734 C.Anton and Making Potions(二分)
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions
- Codeforce#379C. Anton and Making Potions(二分or贪心)
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions//734C
- 【HDU-oj】-4920-Matrix multiplication(矩阵,裸)
- 关于hololens调用讯飞语音sdk问题汇总
- Angular开发者指南(一)入门介绍
- poj2251(翻译)
- 在Oracle 11.2.0.3.0上开启大页(hugepages)的详细解析
- 734C Anton and Making Potions
- CentOs 6.5下安装jdk1.7
- i18next的使用
- js基础5应用案例
- Spring中容器的作用域
- Bone Collector_HDU
- ROS探索总结(十四)——move_base(路径规划)
- 列表——更改的是谁
- CrateDB记录_2