Bob's Print Service

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
Bob is providing print service,while the pricing doesn't seem to be reasonable,so people using her price service found some tricks to save money.
For example,the price when printing lwss than 100 pages is 20 cents per page,but when printing not less than 100 pages,you just need to pay only 10 cents page. It's easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 * 10 cents instead of 99 * 20 cents.
Now given the description of pricing strategy and some queries,your task is to figure out the best ways to complete those queries in order to save money.
输入
The first line contains an integer T(<= 10) which is the number of test cases.
Then T cases follow.
Each case contains 3 lines. The first line contains two integers n,m(0< n,m <10^5).
The second line contains 2n integers S1,P1,S2,P2,……,Sn,Pn(0 = S1 < S2 < …… < Sn <= 10^9 ,
10^9 >= P1 >= P2 …… >= Pn >= 0).
The price when printing no less that S(i) but less that S(i+1) pages is Pi cents per page(for i = 1 …… n-1). The price when printing no less than Sn pages is Pn cents per page.
The third line containing m integers Q1,…… Qm(0 <= Qi <= 10^9) are the queries.
输出
For each query Qi,you should output the minimum amount of money(int cents) to pay if you want to print Qi pages, one output in one line.
样例输入
1
2 3
0 20 100 10
0 99 100
样例输出
0
1000
1000

题意:先给出两个整数n、m,然后给出n个区间的临界点和大于这个临界点的每张纸的价格。然后给出m个k,问打印纸张数不低于k的最小花费。

解题思路:先预处理一下,用一个数组v记录处理后的结果,v[i]表示打印张数不低于临界点s[i]时所花费的最小的钱数,然后二分查找出不低于要查找的纸张数的位置a,求出打印k张本该支付的钱数ans=k*p[a-1],将ans与记录的v[a]比较,求出的最小值即为最小花费。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL s[N], p[N], v[N];
int main()
{int t, m, n, i, k;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(i = 0; i < n; i++)scanf("%lld%lld",&s[i],&p[i]);for(i = n-1; i >= 0; i--){if(i == n-1)v[i] = s[i] * p[i];elsev[i] = min(v[i+1], s[i] * p[i]);}while(m--){scanf("%d",&k);int a = upper_bound(s, s+n, k) - s;//二分查找,返回查找元素的最后一个可安插位置,即“元素值>查找值”的第一个元素的位置LL ans = k * p[a-1];if(a < n)ans = min(ans, v[a]);printf("%lld\n",ans);}}return 0;
}

NYOJ 933 Bob's Print Service相关推荐

  1. android三星打印插件,三星打印服务插件 Samsung Print Service for Android

    三星手机用户想要使用打印机服务,必须要有插件才行,三星打印服务插件 Samsung Print Service for Android该插件使手机文档打印到许多三星激光打印机,且无需对第三方应用程序或 ...

  2. Mopria Print Service现在可用于统一端点管理解决方案

    Mopria Print Service已登录移动企业集成解决方案平台MobileIron MarketPlace 加州圣拉蒙--(美国商业资讯)--为打印和扫描提供通用标准和解决方案的全球非营利性会 ...

  3. android print service,Mopria Print Service

    Mopria Print Service 介绍 Mopria Print Service Mopria Print Service enables printing on your Android ( ...

  4. 浅谈Android Print Service

        Google 为了支持移动设备打印功能在Android4.4加入了printservice打印框架.既如果你想让你的打印机能够在Android系统上完成打印工作,那么一种可选的方式就是按照Go ...

  5. ros service

    Server部分: #!/usr/bin/env pythonimport sys import osimport rospy #from beginner.srv import * from beg ...

  6. ROS入门笔记(十一):编写与测试简单的Service和Client (Python)

    ROS入门笔记(十一):编写与测试简单的Service和Client (Python) 文章目录 01 导读 02 功能包的创建 03 在功能包中创建自定义服务类型 3.1 定义srv文件 3.2 在 ...

  7. RSS Reader实例开发之使用Service组件

    原文地址::http://www.ophonesdn.com/article/show/122 到目前为止,我们已经实现了RSS Reader的基本功能,在这个OPhone应用程序中,我们使用Acti ...

  8. python中append函数合并列表且列表内数字从高到低_35个高级Python知识点总结

    No.1 一切皆对象 众所周知,Java中强调"一切皆对象",但是Python中的面向对象比Java更加彻底,因为Python中的类(class)也是对象,函数(function) ...

  9. python3 列表取交集_常用序列数据类型列表

    python中有列表.元组.集合.字典这四种可以存放多个数据元素的集合,他们在总体功能上都起着存放数据的作用,却都有着各自的特点.本片文章中我们会对列表的用法做详细说明. 演示环境: python3. ...

最新文章

  1. 打破数据孤岛释放数据价值,腾讯联合安全计算平台重磅出炉
  2. 中电信抢滩云计算 在上海开建“信息银行”
  3. Spring Boot使用Druid和监控配置
  4. .net DataGrid绑定列手动添加数据
  5. HDU2015校赛 The Country List
  6. Python基础day05【函数应用:学生管理系统、拆包、今日总结】
  7. Spring(七)持久层
  8. leetcode 978. Longest Turbulent Subarray | 978. 最长湍流子数组(Java)
  9. P5200 [USACO19JAN]Sleepy Cow Sorting 牛客假日团队赛6 D 迷路的牛 (贪心)
  10. c#中的DefWndProc是Control类的虚函数
  11. 高并发场景下的缓存有哪些常见的问题?
  12. python写520_用Python做一个520表白神器,值得收藏
  13. 【转】矩阵变换坐标系 深入理解
  14. 遍历结构体_三菱ST语言编程(3)——结构体变量
  15. 视频和视频帧:H264编码格式整理
  16. HR看完这种简历就崩溃?真相是这样的!
  17. java Locale类使用
  18. 【学习资源】光学、物理类、电子学实验合集
  19. JAVA中 BufferedImage、ImageIO用法
  20. 带你一步步破解亚马逊 淘宝 京东的反爬虫机制!

热门文章

  1. 20051020:该办宽带了
  2. 华为敏捷DevOps实践:如何从Excel管理软件的方式中走出来
  3. Linux课程第二十一天学习笔记
  4. Ubuntu 下mysql service 启动问题
  5. 存储过程中同一语句多个聚合函数时 into 用法
  6. 判断 iframe 是否加载完成的完美方法
  7. WebLogic下载地址
  8. 机房日常技术总结——Windows篇
  9. 【转载】给不同 type 的 input 自动设置样式
  10. 如何积累自己的技术认知