题目链接: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的更多相关文章

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

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

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

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

  6. UVAlive 6611 Alice's Print Service 二分

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

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

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

  8. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

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

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

  10. 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. (五)qt资源文件

    // 规则: :+添加的前缀/+文件名 ui->actionSave_as->setIcon(QIcon(":/new/Image/face.png"));

  2. WinForm文件说明

    以上位置,双击即可. 界面可以通过拖动控件,也可以通过背后的界面代码去布局. 如果删除了事件代码,界面可能报错,因为界面代码中有未删除的残余(波浪线提示处代码,直接删除即可). 对于多个窗体,Prog ...

  3. Linux设备树(六 memory&chosen节点)

    六 memory&chosen节点 根节点那一节我们说过,最简单的设备树也必须包含cpus节点和memory节点.memory节点用来描述硬件内存布局的.如果有多块内存,既可以通过多个memo ...

  4. 第十三节:Lambda、linq、SQL的相爱相杀(2)

    一. Linq开篇 1.Where用法 linq中where的用法与SQL中where的用法基本一致. #region 01-where用法 { //1. where用法 //1.1 查询账号为adm ...

  5. Spring Security 之API 项目安全验证(基于basic-authentication)

    ===================================Basic Authorization 规范===================================Request ...

  6. 微信小程序 mpvue vant

    Mpvue中使用Vant Weapp组件库 https://segmentfault.com/a/1190000016228410?utm_source=tag-newest 小程序采坑记 mpvue ...

  7. [再寄小读者之数学篇](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{ ...

  8. [物理学与PDEs]第2章第1节 理想流体力学方程组 1.2 理想流体力学方程组

    1.  质量守恒定律: 连续性方程 $$\bee\label{2_1_2_zl} \cfrac{\p\rho}{\p t}+\Div(\rho{\bf u})=0.  \eee$$ 2.  动量守恒定 ...

  9. 爬虫工程师JD归纳

    核心能力归纳 负责:多平台信息的抓取,清洗和分析工作 要求: 熟悉常用开源爬虫框架,如 scrapy / pyspider
 了解基于Cookie的登录原理,熟悉常用的信息抽取技术,如正则表达式.XP ...

  10. C# - 代码重构

    隐藏更多 只暴露集合中供人使用的单一功能,将关于集合的更多功能隐藏掉. 旧版本 public class Animal{    private List<string> LanguageL ...