A - Alice's Print Service

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money. 
For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per 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.
 

Input

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 s 1, p 1 , s 2, p2 , ..., s n, p n (0=s 1 < s 2 < ... < s n ≤ 10 9 , 10 9 ≥ p 1 ≥ p 2 ≥ ... ≥ p n ≥ 0).. The price when printing no less than s i but less than s i+1 pages is p i cents per page (for i=1..n-1). The price when printing no less than s n pages is p n cents per page. The third line containing m integers q 1 .. q m (0 ≤ q i ≤ 10 9 ) are the queries.
 

Output

For each query q i, you should output the minimum amount of money (in cents) to pay if you want to print q i pages, one output in one line.
 

Sample Input

1
2 3
0 20 100 10
0 99 100
 

Sample Output

0
1000
1000
 思路:稍微拿多一点可能更便宜
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define INF 1e18
using namespace std; const int maxn=100500; typedef long long LL; LL s[maxn],p[maxn],h[maxn]; int main()
{
int T,n,m;
LL mid,mmin,res;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
scanf("%I64d%I64d",&s[i],&p[i]);
h[i]=s[i]*p[i];
}
mmin=INF;
for(int i=n-1;i>=0;i--){
mmin=min(s[i]*p[i],mmin);
h[i]=mmin;
}
for(int kk=0;kk<m;kk++){
scanf("%I64d",&mid);
if(mid>=s[n-1]) printf("%I64d\n",mid*p[n-1]);
else{
int t=upper_bound(s,s+n,mid)-s;
res=mid*p[t-1];
res=min(res,h[t]);
printf("%I64d\n",res);
}
}
}
return 0;
}

  

HDU 4791 Alice's Print Service 思路,dp 难度:2的更多相关文章

  1. HDU 4791 Alice's Print Service (2013长沙现场赛,二分)

    Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...

  3. HDU 4791 Alice&#39;s Print Service 水二分

    点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  4. 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  5. Alice's Print Service

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  6. A - Alice's Print Service ZOJ - 3726 (二分)

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  7. UVAlive 6611 Alice's Print Service 二分

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  8. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

  9. HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...

随机推荐

  1. 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 3 章 答案

    判断对错 1.由计算机存储和操作的信息称为数据.2.由于浮点数是非常准确的,所以通常应该使用它们,而不是int.3.像加法和减法这样的操作在mAth库中定义.4.n 项的可能排列的数目等于 n!.5. ...

  2. 嵌入式系统 Boot Loader 技术内幕【转】

    本文转载自:https://www.ibm.com/developerworks/cn/linux/l-btloader/ 本文详细地介绍了基于嵌入式系统中的 OS 启动加载程序 ―― Boot Lo ...

  3. User-Defined Table Types 用户自定义表类型

    Location 数据库--可编程性--类型--用户定义表类型 select one database--> programmability-->types-->user--defi ...

  4. 第五次程序设计作业 C++计算器雏形 调用文件输入输出

    一.C++计算器作业系列链接 第三次作业:C++计算器雏形 第三次作业附加:代码规范 第四次作业:命令行的调用及计算 MyGithub 二.本次作业相关 要求:第五次程序设计作业 根据这一次的作业要求 ...

  5. 02_Flume1.6.0安装及单节点Agent实践

    Flume1.6.0的安装1.上传Flume-1.6.0-tar.gz到待部署的所有机器     以我的为例: /usr/local/src/ 2.解压得到flume文件夹      # tar -x ...

  6. ThreadPool开启多线程时支持最大连接200个(默认为2个),不加则会超时

    //ThreadPool System.Net.ServicePointManager.DefaultConnectionLimit = 200;

  7. json 保存

    with open(mpath,"w") as k: dlist=[] for key in yaml_dict["data"]: dlist.append(y ...

  8. MAC OS 英语朗读功能

    哈哈哈,太神奇了 在命令行中敲say + word ,系统能够自己讲word读出来. 如果是敲的是 say +中文, 就不知道再读什么啦 哈哈哈哈---- 此外,在对应网站选中内容后还可以右击,用sp ...

  9. UI自动化测试篇 :webdriver+ant+jenkins自动化测试实践

    http://www.cnblogs.com/chengtch/p/6063360.html 前面基本弄清楚了webdriver+ testng 的测试环境部署,现在这里记录一下结合ant及jenki ...

  10. Win7下怎么设置让远程桌面连接记住密码下次登录不需再输入

    远程桌面连接功能想必大家都不会陌生吧,特别是使用VPS服务器的用户们经常会用到,为了服务器的安全每次都会把密码设置的很复制,但是这样也有一个麻烦,就是每次要桌面远程连接的时候都要输入这么复杂的密码,很 ...