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 ...
随机推荐
- 「CodePlus 2017 12 月赛」火锅盛宴(模拟+树状数组)
1A,拿来练手的好题 用一个优先队列按煮熟时间从小到大排序,被煮熟了就弹出来. 用n个vector维护每种食物的煮熟时间,显然是有序的. 用树状数组维护每种煮熟食物的数量. 每次操作前把优先队列里煮熟 ...
- JDBC详解(一)
一.相关概念介绍 1.1.数据库驱动 这里驱动的概念和平时听到的那种驱动的概念是一样的,比如平时购买的声卡,网卡直接插到计算机上面是不能用的,必须要安装相应的驱动程序之后才能够使用声卡和网卡,同样道理 ...
- bootstrap.yml与application.yml的区别
说明:其实yml和properties文件是一样的原理,主要是说明application和bootstrap的加载顺序.且一个项目上要么yml或者properties,二选一的存在. Bootstra ...
- graphviz 程序生成多种类型图表详解
简介 一幅图抵得上千言万语,这在描述复杂的计算机系统时尤为正确.当系统环境变得更加复杂时,用图将它们表示出来并记入文档就显得更加重要.例如,虚拟化技术有很多优点,但它们通常会让环境变得更加复杂和更难理 ...
- GO_05:GO语言基础map与函数
1. map 1. 类似其它语言中的哈希表活着字典,以 key-value 形式存储数据 2. key 必须是支持 == 或 != 比较运算的类型,不可以是函数.map 或 slice 3. map ...
- Cloudstack系统配置(三)
系统配置 CloudStack提供一个基于web的UI,管理员和终端用户能够使用这个界面.用户界面版本依赖于登陆时使用的凭证不同而不同.用户界面是适用于大多数流行的浏览器包括IE7,IE8,IE9,F ...
- openresty/1.11.2.1性能测试
测试数据 ab -n -c -k http://127.0.0.1/get_cache_value nginx.conf lua_shared_dict cache_ngx 128m; server ...
- 掌握Markdown
翻译自 https://guides.github.com/features/mastering-markdown/ 转载请注明链接 掌握Markdown Markdown是Github平台上一种轻量 ...
- 把一个IEEE754浮点数转换为IBM370浮点数的C#代码
把一个IEEE754浮点数转换为IBM370浮点数的C#代码. 在这个网页上有古老的IBM370浮点格式的说明. // http://en.wikipedia.org/wiki/IBM_Floatin ...
- Jekins - Hello world,Jekins + Maven + Git + Tomcat 的简单应用
Java Web 工程 新建一个简单的 Java Web 工程,并提交至 GitHub,可参考 Eclipse 提交工程至 GitHub 下载 jekins.war 在 http://mirrors. ...