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. stm32 延时函数 delay_ms 范围

    void delay_us(u32 nus) { u32 temp; SysTick->LOAD=nus*fac_us; //时间加载 SysTick->VAL=0x00; //清空计数器 ...

  2. js中一些关于比较左右两边的值的题目

    alert(typeof(NaN)); alert(typeof(Infinity)); alert(typeof(null)); alert(typeof(undefined)); alert(Na ...

  3. 03_Kafka集群操作

    1.集群配置思路 1)每台节点上要启动一个broker进程,因此要配置每台的server.properties broker id, log.dirs, zookeeper.connect 2) 每台 ...

  4. windows 命令行中使用winrar

    加入环境变量即可 我的电脑右键属性->高级->环境变量->系统变量->编辑 变量名:path 变量值:C:/Program Files/WinRAR; --变量值为WinRAR ...

  5. python 筛选

    data=[,,,,,,,-,-] result=[x ]

  6. JMeter源码导入到Intellij IDEA

    环境: Windows10,jdk1.8,Intellij IDEA 2018.1.5 x64,apache-jmeter-4.0_src.zip  http://jmeter.apache.org/ ...

  7. 转载: 几个主流的Java连接池整理

    https://www.cnblogs.com/linjian/p/4831088.html 池(Pool)技术在一定程度上可以明显优化服务器应用程序的性能,提高程序执行效率和降低系统资源开销.这里所 ...

  8. Codeforces 898F - Restoring the Expression(字符串hash)

    898F - Restoring the Expression 思路:字符串hash,base是10,事实证明对2e64取模会T(也许ull很费时),对1e9+7取模. 代码: #include< ...

  9. 关于怎么解决java.lang.NoClassDefFoundError错误

    五一在部署新的统一登录时,遇到这样一个问题: 很容易把java.lang.NoClassDefFoundError和java.lang.ClassNotfoundException这两个错误搞混,事实 ...

  10. js匿名函数和闭包总结

    js匿名函数和闭包总结 一.总结 一句话总结:匿名函数的最主要作用是创建闭包,闭包就是将函数内部和函数外部连接起来的一座桥梁.内层的函数可以使用外层函数的所有变量,即使外层函数已经执行完毕.闭包可以用 ...