全场最水题。

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

查找的时候,二分同时判断最小值即可。

注意初值的设定应该设定为long long 的无穷大。

#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 100100
typedef long long ll;
using namespace std; ll a[maxn],b[maxn],c[maxn],f[maxn],ans,n,m,t,k,num; ll find(ll x)
{
if (x>=a[n]) return n;
if (x<=a[]) return ;
ll l=,r=n,mid;
while (l<r)
{
mid=(l+r)/;
if (a[mid]>=x) r=mid;
else l=mid+;
}
if (x<a[l]) l--;
return l;
} int main()
{
scanf("%I64d",&t);
while (t--)
{
scanf("%I64d%I64d",&n,&m);
for (ll i=; i<=n; i++)
{
scanf("%I64d%I64d",&a[i],&b[i]);
c[i]=a[i]*b[i];
}
f[n]=c[n];
f[n+]=~0U>>;
f[n+]<<=;
for (ll i=n-; i>=; i--) f[i]=min(f[i+],c[i]);
while (m--)
{
scanf("%I64d",&num);
if (num<a[])
{
printf("%I64d\n",f[]);
continue;
}
k=find(num);
if (k==n)
{
printf("%I64d\n",num*b[n]);
continue;
}
ans=min(num*b[k],f[k+]);
printf("%I64d\n",ans);
}
}
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 &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 ...

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

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

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

  6. Alice's Print Service

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

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

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

  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. Python面向对象之封装、property特性、绑定方法与非绑定方法

    一.封装 ''' 1.什么封装 封:属性对外是隐藏的,但对内是开放的(对内是开放的是因为在类定义阶段这种隐藏已经发生改变) 装:申请一个名称空间,往里装入一系列名字/属性 2.为什么要封装 封装数据属 ...

  2. 总结hibernate框架的常用检索方式

    1.hibernate框架的检索方式有以下几种: OID检索:根据唯一标识OID检索数据 对象导航检索:根据某个对象导航查询与该对象关联的对象数据 HQL检索:通过query接口对象查询 QBC检索: ...

  3. git 自己易忘的命令

    1. git 更新远程分支列表 git remote update origin --prune git remote update origin -p 2. 查看远程分支: git branch - ...

  4. javaweb学习2——HTTP协议

    声明:本文只是自学过程中,记录自己不会的知识点的摘要,如果想详细学习JavaWeb,请到孤傲苍狼博客学习,JavaWeb学习点此跳转 本文链接:https://www.cnblogs.com/xdp- ...

  5. java两年工作经验有什么经验

    这两年里,了解了完整项目的开发过程,知道如何快速入手一个完全没接触过的项目:譬如先了解数据库关系后,马上熟悉一个功能从前端到后端的实现过程,自己再写一个功 能,这样子就能马上上手开发项目,之后在慢慢了 ...

  6. CentOS安装Zabbix Agent

    rpm -i http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm安装存储库 yum ...

  7. Netty源码分析第7章(编码器和写数据)---->第4节: 刷新buffer队列

    Netty源码分析第七章: 编码器和写数据 第四节: 刷新buffer队列 上一小节学习了writeAndFlush的write方法, 这一小节我们剖析flush方法 通过前面的学习我们知道, flu ...

  8. Linux下端口映射工具rinetd

    Linux下简单好用的工具rinetd,实现端口映射/转发/重定向官网地址http://www.boutell.com/rinetd 软件下载wget http://www.boutell.com/r ...

  9. Win7-64位PowerDesigner下MySQLODBC驱动问题

    操作系统:win7-64位,PowerDesigner15.1(以下简称PD), MYSQL-ODBC-64驱动.安装完MYSQL-ODBC-64却找不到相关驱动,用PD反导数据库,却找不到Mysql ...

  10. python2.6更改为Python2.7

    文中为Python2.6.6,改为Python2.6即可,因为没有/usr/bin/python2.6.6,只有/usr/bin/python2.6 http://blog.csdn.net/jcjc ...