hdu4791-Alice's Print Service
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791


题目解释:给你一组数据s1,p1,s2,p2...sn,pn,一个数字q,问你当要打印q张资料时,最少花费是多少?值得注意的是p1>p2>p3>...>pn,就是因为看清这个条件,走了很多弯路。
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; const int N = 1e5 + ;
long long s[N],p[N],ps[N],minn[N],q;
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i++)
{
scanf("%lld%lld",&s[i],&p[i]);
ps[i] = s[i]*p[i];
}
minn[n+] = 1ll<<;//就是因为这
for(int i = n;i >= ;i--)
minn[i] = min(ps[i],minn[i+]);
long long sum;
for(int i = ;i <= m;i++)
{
scanf("%lld",&q);
int pos = lower_bound(s+,s+n+,q) - s;//返回大于或等于val的第一个元素位置
if(pos == )
{
printf("0\n");
continue;
}
if(s[pos] == q)
sum = min(q*p[pos],minn[pos]);
else
sum = min(q*p[pos-],minn[pos]);
printf("%lld\n",sum);
}
}
return ;
}
hdu4791-Alice's Print Service的更多相关文章
- 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 ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- Alice's Print Service
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 ...
- 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.. ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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/showP ...
随机推荐
- 跟我一起写Makefile
跟我一起写Makefile 来源 https://blog.csdn.net/fhaitao900310/article/details/82657193 陈皓 (博客地址:http://blog. ...
- Docker 安装应用
Docker 安装应用 安装 odoo 10 : docker pull postgres:9.6 &&docker pull odoo:10 && docker ru ...
- 川普和习G-20会面为缓和中美贸易战提供了很大的机会
川普和习将于这周在Buenos Aires(阿根廷首都)会面,互相商讨虚弱经济全球化的最大威胁. 自从川普在今年七月第一次开始提高中国商品关税之后,对全球的投资者和逐渐削弱的经济活动来说,两位领导人可 ...
- centos安装node环境
一.安装wget yum install -y wget 二.下载node最新的安装包 wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linu ...
- 使用FFMPEG进行一些视频处理(C#)视频合并、转码、获取时长
FFMPEG的强大无需多说,举几个用到的功能,直接贴代码了 还有更多命令用到时搜索即可 视频转码 ) { var args = "-y -i {0} -vcodec copy {1}&quo ...
- tex中pdf外链
\documentclass{article} \usepackage{hyperref} \begin{document} \href{run:d:/my folder/test.pdf}{This ...
- [再寄小读者之数学篇](2014-06-26 Logarithmical Sobolev inequality using BMO space)
$$\bex q>3\ra \sen{\n f}_{L^\infty} \leq C(q)\sez{ 1+\sen{\n f}_{BMO} \ln^\frac{1}{2}\sex{e+\sen{ ...
- [再寄小读者之数学篇](2014-06-23 Hardy 空间、BMO空间与 Triebel-Lizorkin 空间)
$$\bex 0<p<\infty\ra H_p=\dot F^0_{p,2};\quad BMO=\dot F^0_{\infty,2}. \eex$$ see [H. Triebel, ...
- JavaScript事件的属性列表
HTML 4.0 的新特性之一是能够使 HTML 事件触发浏览器中的行为,比如当用户点击某个 HTML 元素时启动一段 JavaScript.下面是一个属性列表,可将之插入 HTML 标签以定义事件的 ...
- 工作经验-类型转换[ java.lang.String]
错误代码: logger.info("1"); Map<String,String> zxmap = (Map) zxList.get(0); ybty.setFyze ...