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 ...
随机推荐
- lintcode : 二叉树的层次遍历II
题目 二叉树的层次遍历 II 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, ...
- map的详细用法
map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...
- python 解析 xml
<taskList nextId="62292"> <task module="reliability" owner="vprovo ...
- C#五层架构
UI Business Logic Layer Business Rule Layer Data Access Layer Data Definition Layer 简单工厂模式 simple fa ...
- Servlet的应用
1.重定向 HttpServletRequest接口提供的sendRedirect()方法用于生产302响应码和Location响应头,从而通知客户端去重新访问Location响应头中指定的U ...
- c# FastReport开发报表
本文介绍c#应用FastReport开发报表,因此首先附该工具下载地址:http://download.csdn.net/detail/hws1058648831a/6378499 下载解压后可以直接 ...
- 关于imx6核心板qt系统U盘挂载
在使用imx6核心板开发的时候,程序写到U盘,想通过U盘在板子上运行程序,U盘插到板子上后在minicom中有信息显示,但是无法找到挂载文件,/dev和/mnt下都没有找到相应的文件.后来百度后发现U ...
- HDU 4675 GCD of Sequence(容斥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m).对于d(1< ...
- CSS+DIV问题!DIV的最小高度问题!
DIV层的最小高度问题!就是一个DIV有个最小高度,但是如果DIV层中的内容很多,DIV的高度会根据内容而进行拉长!要求IE6.IE7还有firefox都要兼容!我试了很多网上的方法都不好用!请测试后 ...
- [58 Argo]58同城开源web框架Argo搭建实践
无意间听说58开源的消息(Long long ago),我辈欣喜异常. 一方面感谢开源同仁的辛苦劳动,另一方面也为我辈在互联网技术实践圈外的人提供了一条实践的渠道. 我迫不及待的从github上dow ...