HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接:
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791
ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072
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.
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.
1
2 3
0 20 100 10
0 99 100
0
1000
1000
题意:
打印纸张,随着张数的添加,每张的价格非递增,给出
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 & ZOJ 3726 Alice's Print Service (数学 打表)的更多相关文章
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分法+枚举)
主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 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 ...
- 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 ...
- 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 ...
- Alice's Print Service
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...
随机推荐
- HDU 1864最大报销额(一维背包)
题目地址:HDU 1864 刚上来看着挺麻烦的..细致看了看原来好简单好简单...仅仅要去掉一些不符合要求的发票,剩下的就是最简单的背包问题了..对于小数问题,仅仅要*100就变成整数了. 代码例如以 ...
- Build制作模型
#include <iostream> using namespace std; //不知道为什么事实上非常好解释的东西在网上搞的人晕头转向的,下面是我的理解. //一个基类衍生出很多详细 ...
- hdu 4856 Tunnels(bfs+状态压缩)
题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...
- 解决java.sql.SQLException: ORA-01789: query block has incorrect number of result columns
java.sql.SQLException: ORA-01789: query block has incorrect number of result columns at oracle.jdbc. ...
- javascript变量,作用域和内存问题(一)
js对象的引用是很有意思的,引用型对象是不可以直接引用的,我猜测这是原型的来源之一,有大神请详解或斧正. “引用类型的值是保存在内存中的对象.与其他语言不同,JavaScript不允 ...
- Property 和 Attribute 的区别(转)
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...
- vs2015web工程中的html引用压缩后css后无法智能提示的问题解决
环境:win10x64 vs2015企业版 项目:空白web项目(.net framework4) 问题:html页面加入压缩后的css(eg:bootstrap.min.css),编码的时候无法智能 ...
- 朝花夕拾-4-shell
引言 shell,我们常常会用到,以其强大的功能,会帮助我们解决非常多棘手的问题.近期遇到一个问题,要跑非常多case,假设串行的执行,须要非常久.能不能让他们并行起来,但又不能全部case都并行执行 ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- 错误 4 自定义工具错误: 无法生成服务引用“DepartMentService”的代码。请检查其他错
原文:错误 4 自定义工具错误: 无法生成服务引用"DepartMentService"的代码.请检查其他错 问题: 错误 4 自定义工具错误: 无法生成服务引用" ...