题目链接: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(枚举+二分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces gym101612 L.Little Difference(枚举+二分)

    传送:http://codeforces.com/gym/101612 题意:给定一个数n(<=1e18),将n分解为若干个数的成绩.要求这些数两两之间的差值不能大于1. 分析: 若n==2^k ...

  4. Codeforces H. Prime Gift(折半枚举二分)

    题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...

  5. C. Anton and Making Potions 贪心 + 二分

    http://codeforces.com/contest/734/problem/C 因为有两种操作,那么可以这样考虑, 1.都不执行,就是开始的答案是n * x 2.先执行第一个操作,然后就会得到 ...

  6. 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 ...

  7. 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 ...

  8. [二分] Codefoces Anton and Making Potions

    Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  9. CodeForce-734C Anton and Making Potions(贪心+二分)

    CodeForce-734C Anton and Making Potions  C. Anton and Making Potions time limit per test 4 seconds m ...

随机推荐

  1. fzyzojP3618 -- [校内训练-互测20180412]士兵的游戏

    二分图匈牙利也可以 判断必须点就看能不能通过偶数长度的增广路翻过去 代码: (最后一个点4s多才行,,,卡不过算了) 开始边数写少了RE,应该是4*N*N M-R随手开了一堆int?都要是long l ...

  2. 多项式 Wannafly挑战赛22

    后缀表达式 大整数(加法.乘法.gcd java) import java.math.BigInteger; import java.util.Scanner; class Work { String ...

  3. BRIEF特征点描述子

    简介 BRIEF是2010年的一篇名为<BRIEF:Binary Robust Independent Elementary Features>的文章中提出,BRIEF是对已检测到的特征点 ...

  4. include动作和include指令的区别

    1. include指令在被导入页面时,会与原有的jsp代码完全融合,共同生成同一个Servlet:而include动作则会在原有的jsp代码使用include方法而被导入页面,所以includ指令在 ...

  5. 【转】MYSQL数据库设计规范与原则

    转载出:http://www.cnblogs.com/lovekingly/p/5044278.htmlMYSQL数据库设计规范 1.数据库命名规范 采用26个英文字母(区分大小写)和0-9的自然数( ...

  6. VBscript.Encode 解码器

    VBscript.Encode 解码器   此解码器算法来至互联网,我只是收集然后写了个简单的页面便于大家使用. 如有何不妥之处,请留言.

  7. 在cygwin下安装ns2

    首先下载ns2.可以到sourceforge去下载最新的all-in-one版本2.31,url为http://sourceforge.net/project/showfiles.php?group_ ...

  8. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot ...

  9. jQuery基础之二(操作标签)

    一:样式操作 addClass();// 添加指定的CSS类名. removeClass();// 移除指定的CSS类名. hasClass();// 判断样式存不存在 toggleClass();/ ...

  10. php的几个面试题

    1. mysql_num_fields() 返回结果集中字段的数目 如: $result = mysql_query("SELECT id,name,age FROM mydb.tb1 wh ...