Codeforces 734C Anton and Making Potions(枚举+二分)
题目链接:http://codeforces.com/problemset/problem/734/C
题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,
第一类周瑜有m种,每种咒语使制作一个药的时间变成a[i],花费b[i]的魔力,
第二类咒语有k种,每种咒语瞬间产生c[i]个药,花费d[i]的魔力,c[i]和d[i]都是不递减的,
求最短时间内产生n个药的时间。
解题思路:
因为c[i]和d[i]都是不降的,所以可以枚举a[i],然后二分查找花费小于t-b[i]的第二类咒语。
注意这里要用upper_bound()而不能用lower_bound(),比如
10 12
82 82
前者会找到12,而后者会找到10。
代码:
#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
const double eps=1e-; LL n,m,k,x,s;
LL a[N],b[N],c[N],d[N]; int main(){
FAST_IO;
cin>>n>>m>>k>>x>>s;
for(int i=;i<=m;i++){
cin>>a[i];
}
for(int i=;i<=m;i++){
cin>>b[i];
}
for(int i=;i<=k;i++){
cin>>c[i];
}
for(int i=;i<=k;i++){
cin>>d[i];
} LL ans=x*n; //初始化为不用魔法所需时间
a[]=x; for(int i=;i<=m;i++){
//魔力值不够
if(b[i]>s) continue;
LL t=s-b[i];
int pos=upper_bound(d+,d++k,t)-d;
pos--;
ans=min(ans,a[i]*(n-c[pos]));
}
cout<<ans<<endl;
return ;
}
Codeforces 734C Anton and Making Potions(枚举+二分)的更多相关文章
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- Codeforces 734C. Anton and Making Potions(二分)
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass ...
- Codeforces gym101612 L.Little Difference(枚举+二分)
传送:http://codeforces.com/gym/101612 题意:给定一个数n(<=1e18),将n分解为若干个数的成绩.要求这些数两两之间的差值不能大于1. 分析: 若n==2^k ...
- Codeforces H. Prime Gift(折半枚举二分)
题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...
- C. Anton and Making Potions 贪心 + 二分
http://codeforces.com/contest/734/problem/C 因为有两种操作,那么可以这样考虑, 1.都不执行,就是开始的答案是n * x 2.先执行第一个操作,然后就会得到 ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分
题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分
C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...
- [二分] Codefoces Anton and Making Potions
Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- CodeForce-734C Anton and Making Potions(贪心+二分)
CodeForce-734C Anton and Making Potions C. Anton and Making Potions time limit per test 4 seconds m ...
随机推荐
- 【数学】【CF1096C】 Polygon for the Angle
Description 给定一个角度 \(\theta\),请你寻找一个正 \(n\) 边型,满足在这个正 \(n\) 边型上找三个顶点 \(A,B,C\) (可以不相邻),使得 \(\angle A ...
- struts的问题
将SSH框架进行整合的时候,将三者的jar包加入到lib下面,然后测试struts,结果页面显示不出来报404错误,可是路径没有问题 找到罪魁祸首是:原因两个:(1)在未用到spring的时候,先不要 ...
- 野指针(Wild pointer)和悬垂指针(dangling pointer)
详细参考如下: Dangling pointer(悬垂指针.迷途指针)和 Wild pointer(野指针) 迷途指针经常出现在混杂使用malloc() 和 free() 库调用: 当指针指向的内存释 ...
- P2657 [SCOI2009]windy数
P2657 [SCOI2009]windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B ...
- P3007 [USACO11JAN]大陆议会The Continental Cowngress
P3007 [USACO11JAN]大陆议会The Continental Cowngress 题意: 给出 n 个法案, m 头牛的意见, 每头牛有两个表决 格式为 "支持或反对某法案&q ...
- nc命令的常用参数介绍
nc命令的常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想必做运维的应该在网络安全上都对一些开源软件都应该是相当的了解吧,比如tcpdump,namp等神奇,今天要给 ...
- 转:UIView的sizeToFit与sizeThatFits
UILabel经常用到的方法- (void)sizeToFit- (CGSize)sizeThatFits:(CGSize)size解释如下: sizeToFit会自动调用sizeThatFits方法 ...
- 科学计算三维可视化---Mlab基础(数据可视化)
推文:科学计算三维可视化---TVTK库可视化实例 使用相关函数:科学计算三维可视化---Mlab基础(管线控制函数) 一:mlab.pipeline中标量数据可视化 通过持续实例,来感受mlab对数 ...
- windows安装filebeat服务报错
cmd进入filebeat目录下 用以下命令执行: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-fil ...
- MySQL学习(二)——MySQL多表
分页操作:使用limit(参数1,参数2) 起始位置(参数1))*每页显示的条数(参数2) .分类表 create table category( cid ) primary key, cname ) ...