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/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
2013 Asia Changsha Regional Contest


题意:

打印纸张,随着张数的添加,每张的价格非递增,给出 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;
}


转载于:https://www.cnblogs.com/mengfanrong/p/4292488.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/375297.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

夺命雷公狗---ECSHOP---08---商品页的拇改成星星

<strong>用户评价&#xff1a;</strong>{*---------商品评价星星开始----------*}<img src"./images/stars{$goods.comment_rank}.gif" alt"comment rank {$goods.comment_rank}">{*---------商品评价星星结束-------*} 这里主要是要有星…

文件指针

一.移动文件指针 SetFilePointer,hFile,lDistanceToMove,lpDistanceToMoveHigh,dwMoveMethod dwMoveMethod 指明移动的模式 FILE_BEGIN 不管文件处于什么地方,总是从文件的头部开始移动,这时的位置参数相当于指定了一个绝对位置 FILE_CURRENT 从当前的文件指针处开始移…

见证下的自我变化-2014全年总结

又是一年总结季&#xff0c;回过头看看看自己的成长&#xff0c;心里真的是满满的喜悦之情…… 一年前自己的总结博客&#xff1a;http://blog.csdn.net/huo065000/article/details/19632603 半年前自己的总结博客&#xff1a;http://blog.csdn.net/huo065000/article/details/…

【Linux学习篇】This virtual machine is configured for 64-bit guest operating systems.……

在学习Linux的基本操作的时候&#xff0c;安装虚拟环境则提示自己 This virtualmachine is configured for 64-bit guest operatingsystems.……起初由于各种拒绝的心理&#xff0c;所以屏蔽了这个错误&#xff0c;但是屏蔽永远也解决不了问题的&#xff0c;所以自己则尝试百度…

图解SSIS监视文件夹并自动导入数据

图解SSIS监视文件夹并自动导入数据 原文:图解SSIS监视文件夹并自动导入数据 演示案例&#xff1a;让系统自动监视文件夹&#xff0c;并把文件夹下面的excel文件导入到sql中&#xff0c;之后清空目录。这个过程以往都需要写程序来实现或者定时执行&#xff0c;现在可以用ssis来订…

DLL转Lib

在C中,为了允许操作符重载和函数重载,C编译器往往按照某种规则改写每一个入口点的符号名,以便使用同一个名字(具有不同的参数类型或者是不同的作用域)有多种不同的用法,而不会打破现有基于C的链接器,.这项技术通常被称为改编(Name Mangling)或者名称修饰(Name Decoration),许多…

WP8手机解锁时提示“请确保IPOVERUSBSVC服务正常运行”解决方法

如果你各种重启服务 卸载手机 重装驱动都试过了还不行&#xff0c;请看看你是否安装了Hyper-v或Vitualbox虚拟机&#xff0c;很有可能是虚拟交换机造成的。 我在网络连接属性里看到这个 把它卸载后&#xff0c;解锁成功。 解锁后记得重新安装卸载的那个网络服务转载于:https://…

Win32路径操作相关API

一.路径截断与合并 PathRemoveArgs 去除路径的参数 PathRemoveBackslash 去除路径最后的反斜杠 "\" PathAddBackslash 在路径最后加上反斜杠 "\" PathRemoveBlanks 去除路径前后的空格 PathAddExtension 在文件路径后面加上扩展名 PathRemoveExtension 去…

Openjudge-计算概论(A)-称体重

描述&#xff1a; 赵、钱、孙、李四个人中既有大人也有小孩&#xff0c;给他们称体重时发现&#xff0c;他们每个人的体重都不一样&#xff0c;且体重&#xff08;单位&#xff1a;公斤&#xff09;恰好是10的整数倍&#xff0c;且他们的体重都不高 于50公斤&#xff0c;已知赵…

浮点数的存储

-------------------------------------------------------------------------------- 在VC6.0----float环境一共32位 其中第一位是符号位 第二到第9位中间8位为小数点位置&#xff08;指数以127的二进制为原点向下为负指数 向上为正指数&#xff09;后面23位为数据位。 S EE…

第二阶段总结

结合第二阶段后3天&#xff0c;我们试用了UI&#xff0c;antionbar&#xff0c;menu等实用&#xff0c;成功的做出了字体的转换&#xff0c;题目的转化等功能。 其实四则运算&#xff0c;说难不难 说易不易&#xff0c;总结出 主要有付出&#xff0c;就有回报。 menu等做的过程…

const 和指针

c用了那么久&#xff0c;觉得 const 和指针配合到一起的时候就会有点点分不出来。 如下: const Data* pData;Data const * pDataData * const pDataconst Data * const pData Data const * const pData是不是有点晕&#xff1f; 我其实用得最多的是 const Data* pData, 也…

Linux 查看系统用户的登录日志

查看用户登录系统的日志有两类日志记录用户登录的行为&#xff0c;一是记录登录者的数据&#xff0c;一个是记录用户的登录时间一&#xff0c;记录用户登录数据/var/log/wtmp日志文件记录用户登录的数据。但这个文件是被编码的文件&#xff0c;不能直接用vi、cat等命令查看&…

Android -- 自定义权限

在android系统的安全模型中&#xff0c;应用程序在默认的情况下不可以执行任何对其他应用程序&#xff0c;系统或者用户带来负面影响的操作。如果应用需要执行某些操作&#xff0c;就需要声明使用这个操作对应的权限。 &#xff08;在manifest文件中 添加标记&#xff09;。 ap…

Win32 路径操作API

路径操作相关API 路径截断与合并函数 PathRemoveArgs 去除路径的参数 PathRemoveBackslash 去除路径最后的反斜杠“\” PathAddBackslash 在路径最后加上反斜杠“\” PathRemoveBlanks 去除路径前后的空格 PathAddExtension 在文件路径后面加上扩展名 Pa…

dbms_output.put_line长度限制问题

dbms_output.put_line长度限制问题对于10g以上版本(包括10g), dbms_output.put_line的最大长度限制是32767. 如果报错buffer overflow, 执行如下语句即可:set serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED对于10g以下版本dbms_output.put_line最大长度限制是255.转载于…

js深入研究之Person类案例

<script type"text/javascript"> /* 定义一个Person类 */ function Person(name, age) {this.name name;this.age age; } /* 添加两个方法getName getAge */ Person.prototype {getName: function() {return this.name;},getAge: function() {return this.a…

C++名称粉碎

C name mangling 1: ?0: 构造器&#xff0c;?1 析构器 2: QAE: public __thiscall AAE: private __thiscall QBE: public __thiscall const 3: 返回值和参数类型 B&#xff1a;const D&#xff1a;char E&#xff1a;unsigned char F&#xff1a;…

一款基于css3鼠标经过圆形旋转特效

今天给大家分享一款基于css3鼠标经过圆形旋转特效。当鼠标经过的时候图片边框颜色旋转&#xff0c;图片显示详情。该实例适用浏览器&#xff1a;IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗。效果图如下&#xff1a; 在线预览 源码下载 实现的代码。 ht…

Delphi与Windows 7下的用户账户控制(UAC)机制

WIN7/WIN8/WIN10, Vista提供的UAC机制&#xff0c;它的主要目的是防止对于操作系统本身的恶意修改。 对于Delphi程序的影响&#xff0c;UAC主要在于以下几点&#xff1a; 1、由于UAC机制&#xff0c;Delphi对于系统的操作可能无声的失败&#xff0c;而同样的程序&#xff0c;在…