Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C
题意:
玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果;
对应使用a1[i]魔法需要a2[i]金币,使用b1[i]魔法需要b2[i]金币;
每种魔法最多只能使用一次,问升到n(n<=1e+5)级最少需要多少时间;
注意:给出的b1, b2数组是升序排列的;
思路:对每一个a魔法找到最大的b1魔法jj, 即为使用此a魔法需要最少时间的情况;再找到所有jj中最小的即为答案;
因为b数组是排好序的,所以对于b数组的查找我们可以用二分;时间复杂度为nlog(n);
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define ll long long
#define MAXN 200009
using namespace std; ll min(ll a, ll b){
return a<b?a:b;
} int main(void){
int m1, m2;
ll aim, t, money, ans, a1[MAXN], a2[MAXN], b1[MAXN], b2[MAXN];
scanf("%lld%d%d%lld%lld", &aim, &m1, &m2, &t, &money);
for(int i=; i<m1; i++){
scanf("%lld", &a1[i]);
}
for(int i=; i<m1; i++){
scanf("%lld", &a2[i]);
}
for(int i=; i<m2; i++){
scanf("%lld", &b1[i]);
}
for(int i=; i<m2; i++){
scanf("%lld", &b2[i]);
}
ans=t*aim;
for(int i=; i<m1; i++){
ll gg=aim, mm=money;
if(a2[i]<=mm&&a1[i]<t){
ll tt=a1[i];
mm-=a2[i];
int pos=upper_bound(b2, b2+m2, mm)-b2;
if(pos>=m2){
gg-=b1[m2-];
}else if(pos>){
gg-=b1[pos-];
}
ll jj=gg*tt;
ans=min(ans, jj);
}
{
ll gg1=aim;
int pos=upper_bound(b2, b2+m2, money)-b2;
if(pos>=m2){
gg1-=b1[m2-];
}else if(pos>){
gg1-=b1[pos-];
}
ll jj=gg1*t;
ans=min(ans, jj);
}
}
printf("%lld\n", ans);
return ;
}
Codeforces Round #324 (Div. 2) C (二分)的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #551 (Div. 2) E 二分 + 交互
https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2 ...
- Codeforces Round #350 (Div. 2) D2 二分
五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..D1是个数据规模较小的题 写了一个暴力过了 面对数据如此大的D2无可奈何 现在回来看 一下子就知道解法了 二分就可以 二分能做多 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
随机推荐
- php中向mysql插入数据
$sql='insert into news(title,subtitle,source,publishtime,content,image,author) values("'.unico ...
- 关于JavaScript中对象的继承实现的学习总结
一.原型链 JavaScript 中原型链是实现继承的主要方法.其主要的思想是利用原型让一个引用类型继承另一个引用类型的属性和方法.实现原型链有一种基本模式,其代码如下. function Super ...
- HDU 5071 Chat(2014鞍山赛区现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...
- [转载]javascript创建对象的几种方式
原文链接:http://qingfeng825.iteye.com/blog/1935648 1. 工厂方法:能创建并返回特定类型对象的工厂函数(factory function). function ...
- linux kernel 平台总线实例分析
linux 平台总线的实现有三大块 , platform bus , platform device , platform drvice 平台类型结构体: /** * struct bus_type ...
- 求教Sublime Text2 SublimeLinter插件安装问题
昨天装了 SublimeLinter插件(代码语法检测),这个事插件的地址:https://github.com/Kronuz/SublimeLinter 按照作者的介绍配置了一下,发现语法检测不起作 ...
- iOS 深入理解UINavigationController 和 UIViewController 之间的关系
创建三个类 BasicViewController : UIViewController SecondViewController : UIViewController ThirdViewContro ...
- Game of Life I & II
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...
- Ubuntu里面软件的安装与卸载
在Ubuntu里面,有时候碰到软件配置错了,这是重新再安装的话,会检测到已安装,系统不会再重新安装,就需要卸载之后重装 1.通过deb包安装的情况: 安装.deb包: 代码:sudo dpkg -i ...
- oracle/node-oracledb 数据库驱动 与 Meteor 驱动包!
oracle/node-oracledb: https://github.com/oracle/node-oracledb Oracle 官方维护. metstrike/meteor-oracle ...