CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题
对于这题笔者无解,只有手抄一份正解过来了:
基本思想就是 :
- 二分答案,对于第x天,计算它最少的花费f(x),<=s就是可行的,这是一个单调的函数,所以可以二分。
- 对于f(x)的计算,我用了nlog(n)的算法,遍历m个商品,用c[i]乘以前x天里,第t[i]种货币的最便宜的价格,存放到一个数组里,之后排序,计算前k个的和就是f(x)
- 前x天里,第t[i]种货币的最便宜的价格是通过预处理得到的,很容易的计算一下前缀最小值就行了。
贴代码吧:
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
#define fi first
#define se second
#define mp make_pair
const int maxn = ;
int a[maxn],b[maxn],t[maxn],c[maxn];
int n,m,k,s;
int am[maxn],bm[maxn];
int ida[maxn],idb[maxn];
const int inf = 0x3f3f3f3f; pii pli[maxn];
int id[maxn]; ll f(int x){
ll ret = ;
for (int i=;i<=m;i++){
if (t[i] == ){
pli[i].fi = (ll)c[i] * (ll)am[x]; }
else{
pli[i].fi = (ll)c[i] * (ll)bm[x];
}
pli[i].se = i;
}
sort(pli+,pli+m+);
for (int i=;i<=k;i++){
ret += pli[i].fi;
} return ret;
} int main(){
cin>>n>>m>>k>>s;
am[] = bm[] = inf;
for (int i=;i<=n;i++){
scanf("%d",&a[i]);
if (a[i] < am[i-]){
am[i] = a[i];
ida[i] = i;
}
else{
am[i] = am[i-];
ida[i] = ida[i-];
}
}
for (int i=;i<=n;i++){
scanf("%d",&b[i]);
if (b[i] < bm[i-]){
bm[i] = b[i];
idb[i] = i;
}
else{
bm[i] = bm[i-];
idb[i] = idb[i-];
}
}
for (int i=;i<=m;i++){
scanf("%d%d",&t[i],&c[i]);
} ll low,high,mid;
low = ,high = n;
ll d = -;
while(low <= high){
mid = (low + high) / (ll);
if (f(mid) <= s){
high = mid - ;
d = mid;
for (int i=;i<=k;i++){
id[i] = pli[i].se;
}
}
else{
low = mid + ;
}
}
cout << d <<"\n";
if (d == (ll)-)
return ;
int x = (int)d;
for (int i=;i<=k;i++){
printf("%d %d\n",id[i],t[id[i]]==?ida[x]:idb[x]);
} return ;
}
CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题的更多相关文章
- Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分,贪心
D. Gadgets for dollars and pounds 题目连接: http://www.codeforces.com/contest/609/problem/C Description ...
- CF# Educational Codeforces Round 3 D. Gadgets for dollars and pounds
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes
B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
随机推荐
- mysql字段的适当冗余有利于提高查询速度
CREATE TABLE `comment` ( `c_id` int(11) NOT NULL auto_increment COMMENT '评论ID', `u_id` int(11) NOT ...
- 张小龙谈如何写E-mail软件
编者语:鼎鼎大名的Foxmail软件制作者,你一定不会陌生吧!本刊第三期特刊还刊登过此君的生活照一张,可谓威风八面.小编此次突发奇想,“死缠烂打”,费了九牛二虎之力,终于约他写了一篇有关写E-mail ...
- JavaScript DOM编程基础精华02(window对象的属性,事件中的this,动态创建DOM,innerText和innerHTML)
window对象的属性1 window.location对象: window.location.href=‘’;//重新导航到新页面,可以取值,也可以赋值. window.location.reloa ...
- 使用 Spring 3 来创建 RESTful Web Services(转)
使用 Spring 3 来创建 RESTful Web Services 在 Java™ 中,您可以使用以下几种方法来创建 RESTful Web Service:使用 JSR 311(311)及其参 ...
- 57. Insert Interval
题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if nec ...
- OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务
OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务 1. OpenVAS基础知识 OpenVAS(Open Vulnerability Assessment Sys ...
- PCL—低层次视觉—关键点检测(rangeImage)
关键点又称为感兴趣的点,是低层次视觉通往高层次视觉的捷径,抑或是高层次感知对低层次处理手段的妥协. ——三维视觉关键点检测 1.关键点,线,面 关键点=特征点: 关键线=边缘: 关键面=foregro ...
- 【c】time.h
表示时间的三种类型 日历时间:从一个时间点到现在的秒数,用time_t表示 始终滴答时间:从进程启动到现在时钟的滴答数(每秒一般包含1000个).用clock_t表示 分解时间:分解的数据结构如下.用 ...
- nyoj-257 郁闷的C小加(一) 前缀表达式变后缀
郁闷的C小加(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说 ...
- rundeck email配置文件配置
最近工作中用到了一个任务管理软件rundeck,其中有个很重要的功能就是任务执行提醒,用邮件执行,其中一些配置项,官网没有详细的说明,在网上也没有一个整体的说明,在次跟大家共享下,rundeck的使用 ...