题目链接:

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072

Problem 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 ≤ 105 ). The second line contains 2n integers s1, p1 , s2, p2 , ..., sn, pn (0=s1 < s2 <
... < sn ≤ 109 , 109 ≥ p1 ≥ p2 ≥ ... ≥ pn ≥ 0).. The price when printing no less than si but less than si+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 ≤ 109 ) are the queries.
 
Output
For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.
 
Sample Input
1
2 3
0 20 100 10
0 99 100
 
Sample Output
0
1000
1000
 
Source

题意:

打印纸张,随着张数的添加,每张的价格非递增,给出
m 个询问打印的张数,求出最小的花费。

PS:

保留打印a[i]份分别须要的钱,从后往前扫一遍,保证取得最优解。

然后再找到所打印的张数的区间,与没有多打印,仅仅打印m张所需的花费比較!

HDU代码例如以下:

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define INF 1e18
using namespace std; const int maxn=100017;
typedef __int64 LL; LL s[maxn],p[maxn],c[maxn]; int main()
{
int T;
int n, m;
LL tt;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++)
{
scanf("%I64d%I64d",&s[i],&p[i]);
} LL minn = INF;
for(int i = n-1; i >= 0; i--)
{
minn = min(s[i]*p[i],minn);
c[i] = minn;
}
for(int i = 0; i < m; i++)
{
scanf("%I64d",&tt);
if(tt>=s[n-1])//最后
printf("%I64d\n",tt*p[n-1]);
else
{
int pos = upper_bound(s,s+n,tt)-s;
LL ans = tt*p[pos-1];
ans = min(ans,c[pos]);
printf("%I64d\n",ans);
}
}
}
return 0;
}

ZJU代码例如以下:

#include <cstdio>
#include <algorithm>
#include <iostream>
#define INF 1e18
using namespace std; const int maxn = 100017;
typedef long long LL; LL s[maxn], p[maxn], c[maxn]; int main()
{
int T;
int n, m;
LL tt;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++)
{
scanf("%lld%lld",&s[i],&p[i]);
} LL minn = INF;
for(int i = n-1; i >= 0; i--)
{
minn = min(s[i]*p[i],minn);
c[i] = minn;
}
for(int i = 0; i < m; i++)
{
scanf("%lld",&tt);
if(tt>=s[n-1])//最后
printf("%lld\n",tt*p[n-1]);
else
{
int pos = upper_bound(s,s+n,tt)-s;
LL ans = tt*p[pos-1];
ans = min(ans,c[pos]);
printf("%lld\n",ans);
}
}
}
return 0;
}

HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)的更多相关文章

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

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

  2. HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)

    主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...

  3. HDU 4791 Alice's Print Service 思路,dp 难度:2

    A - Alice's Print Service Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

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

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

  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. Alice's Print Service

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

  8. UVAlive 6611 Alice's Print Service 二分

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

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

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

随机推荐

  1. 如何更好地理解和使用Github

    只知道几乎在顶部看到一对Github用通俗易懂的解释: 你或许不懂怎样造一辆凯迪拉克,但你能够驾驶凯迪拉克. 你或许不懂Evernote是用什么技术做出来的,但你也能够使用Evernote. 你或许不 ...

  2. oracle 解锁scott账户

    安装oracle数据库的时候忘了解锁账户,再加上一直配置不成功,链接不上,最后终于配置好了,发现没账户可用,oracle好难. oracle版本是 Oracle Database 11g Enterp ...

  3. 第十二章——SQLServer统计信息(2)——非索引键上统计信息的影响

    原文:第十二章--SQLServer统计信息(2)--非索引键上统计信息的影响 前言: 索引对性能方面总是扮演着一个重要的角色,实际上,查询优化器首先检查谓词上的统计信息,然后才决定用什么索引.一般情 ...

  4. linux下串口调试工具/串口终端推荐: picocom

    对于picocom, kermit, minicom, picocom 最简单易用,也全然符合我的使用需求. 安装(mint / ubuntu): $ sudo apt-get install pic ...

  5. 泛泰A860(高通公司8064 cpu 1080p) 拂4.4中国民营recovery TWRP2.7.1.2文本(通过刷第三版)

    专业第三方开发团队 VegaDevTeam  (本team 由 syhost suky zhaochengw(z大) xuefy(大星星) tenfar(R大师) loogeo crazyi(天下无雪 ...

  6. 看你的门-攻击服务器(4)-HTTP参数注入攻击

    首先需要声明.这纯粹是没有远见和有点真才实学开发一个愚蠢的观点,只为web参考系统安全. 1.HTTP参数注入攻击 參数,被用做后端HTTP请求中的參数,这个时候就有可能会导致HTTP參数注入. 一个 ...

  7. Nginx + IIS 配置,实现负载均衡

    当你的Web应用程序访问量大的时候,一台服务器可能会因为压力过大而无法处理所有的请求.此时,可以增加服务器,采用负载均衡来分担所有的请求.关于Nginx的作用,自行百度了解.总之,在Windows平台 ...

  8. Ehcache详细解读(转)

    Ehcache 是现在最流行的纯Java开源缓存框架,配置简单.结构清晰.功能强大,最初知道它,是从Hibernate的缓存开始的.网上中文的EhCache材料 以简单介绍和配置方法居多,如果你有这方 ...

  9. 读改善c#代码157个建议:建议13~15

    目录: 建议13:为类型输出格式化字符串 建议14:正确实现浅拷贝和深拷贝 建议15:使用dynamic来简化反射实现 一.建议13:为类型输出格式化字符串 有些类型需要我们根据业务需求提供字符串的格 ...

  10. MemberwishClone学习

    /* * Created by SharpDevelop. * User: My little flower basket * Date: 2013/7/12 * Time: 9:37 * * To ...