对于这题笔者无解,只有手抄一份正解过来了:

基本思想就是 :

  • 二分答案,对于第x天,计算它最少的花费f(x),<=s就是可行的,这是一个单调的函数,所以可以二分。
  • 对于f(x)的计算,我用了nlog(n)的算法,遍历m个商品,用c[i]乘以前x天里,第t[i]种货币的最便宜的价格,存放到一个数组里,之后排序,计算前k个的和就是f(x)
  • 前x天里,第t[i]种货币的最便宜的价格是通过预处理得到的,很容易的计算一下前缀最小值就行了。

贴代码吧:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <algorithm>
  6. using namespace std;
  7. typedef long long ll;
  8. typedef pair<ll,int> pii;
  9. #define fi first
  10. #define se second
  11. #define mp make_pair
  12. const int maxn = ;
  13. int a[maxn],b[maxn],t[maxn],c[maxn];
  14. int n,m,k,s;
  15. int am[maxn],bm[maxn];
  16. int ida[maxn],idb[maxn];
  17. const int inf = 0x3f3f3f3f;
  18.  
  19. pii pli[maxn];
  20. int id[maxn];
  21.  
  22. ll f(int x){
  23. ll ret = ;
  24. for (int i=;i<=m;i++){
  25. if (t[i] == ){
  26. pli[i].fi = (ll)c[i] * (ll)am[x];
  27.  
  28. }
  29. else{
  30. pli[i].fi = (ll)c[i] * (ll)bm[x];
  31. }
  32. pli[i].se = i;
  33. }
  34. sort(pli+,pli+m+);
  35. for (int i=;i<=k;i++){
  36. ret += pli[i].fi;
  37. }
  38.  
  39. return ret;
  40. }
  41.  
  42. int main(){
  43. cin>>n>>m>>k>>s;
  44. am[] = bm[] = inf;
  45. for (int i=;i<=n;i++){
  46. scanf("%d",&a[i]);
  47. if (a[i] < am[i-]){
  48. am[i] = a[i];
  49. ida[i] = i;
  50. }
  51. else{
  52. am[i] = am[i-];
  53. ida[i] = ida[i-];
  54. }
  55. }
  56. for (int i=;i<=n;i++){
  57. scanf("%d",&b[i]);
  58. if (b[i] < bm[i-]){
  59. bm[i] = b[i];
  60. idb[i] = i;
  61. }
  62. else{
  63. bm[i] = bm[i-];
  64. idb[i] = idb[i-];
  65. }
  66. }
  67. for (int i=;i<=m;i++){
  68. scanf("%d%d",&t[i],&c[i]);
  69. }
  70.  
  71. ll low,high,mid;
  72. low = ,high = n;
  73. ll d = -;
  74. while(low <= high){
  75. mid = (low + high) / (ll);
  76. if (f(mid) <= s){
  77. high = mid - ;
  78. d = mid;
  79. for (int i=;i<=k;i++){
  80. id[i] = pli[i].se;
  81. }
  82. }
  83. else{
  84. low = mid + ;
  85. }
  86. }
  87. cout << d <<"\n";
  88. if (d == (ll)-)
  89. return ;
  90. int x = (int)d;
  91. for (int i=;i<=k;i++){
  92. printf("%d %d\n",id[i],t[id[i]]==?ida[x]:idb[x]);
  93. }
  94.  
  95. return ;
  96. }

CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题的更多相关文章

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

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

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

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

  5. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

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

  9. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

随机推荐

  1. lintcode : 二叉树的层次遍历II

    题目 二叉树的层次遍历 II 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, ...

  2. map的详细用法

     map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...

  3. python 解析 xml

    <taskList nextId="62292"> <task module="reliability" owner="vprovo ...

  4. C#五层架构

    UI Business Logic Layer Business Rule Layer Data Access Layer Data Definition Layer 简单工厂模式 simple fa ...

  5. Servlet的应用

    1.重定向     HttpServletRequest接口提供的sendRedirect()方法用于生产302响应码和Location响应头,从而通知客户端去重新访问Location响应头中指定的U ...

  6. c# FastReport开发报表

    本文介绍c#应用FastReport开发报表,因此首先附该工具下载地址:http://download.csdn.net/detail/hws1058648831a/6378499 下载解压后可以直接 ...

  7. 关于imx6核心板qt系统U盘挂载

    在使用imx6核心板开发的时候,程序写到U盘,想通过U盘在板子上运行程序,U盘插到板子上后在minicom中有信息显示,但是无法找到挂载文件,/dev和/mnt下都没有找到相应的文件.后来百度后发现U ...

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

  9. CSS+DIV问题!DIV的最小高度问题!

    DIV层的最小高度问题!就是一个DIV有个最小高度,但是如果DIV层中的内容很多,DIV的高度会根据内容而进行拉长!要求IE6.IE7还有firefox都要兼容!我试了很多网上的方法都不好用!请测试后 ...

  10. [58 Argo]58同城开源web框架Argo搭建实践

    无意间听说58开源的消息(Long long ago),我辈欣喜异常. 一方面感谢开源同仁的辛苦劳动,另一方面也为我辈在互联网技术实践圈外的人提供了一条实践的渠道. 我迫不及待的从github上dow ...