全场最水题。

保留打印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无参装饰器

    需求:想要在test_func函数前后执行一些代码   1.第一步(定义函数,将调用原函数,使用新函数替换) def test_func(): return 'test_func' def test_ ...

  2. 从hs_strcpy谈安全——缓冲区溢出

    对于大多数的博友来说,hs_strcpy一定会很陌生,因为这个hs_strcpy这个关键字和我的工作有挂钩.本来目前就职于恒生电子,hs_strcpy是中间件中公司定义的字符串拷贝方法,在工作业余之余 ...

  3. Python 的AES加密与解密-需要安装的模块

    踩雷1: #先导入所需要的包 pip3 install Crypto #再安装pycrtpto pin3 install pycrypto from Crypto.Cipher import AES ...

  4. 怎样注册Docker Hub账号

    Docker Hub是Docker的远程镜像仓库,类似于GitHub;如果没有搭建本地私有仓库,Docker会默认去Docker Hub拉镜像. 访问Docker Hub官网https://hub.d ...

  5. JUC——线程同步辅助工具类(Exchanger,CompletableFuture)

    Exchanger交换空间 如果现在有两个线程,一个线程负责生产数据,另外一个线程负责消费数据,那么这个两个线程之间一定会存在一个公共的区域,那么这个区域的实现在JUC包之中称为Exchanger. ...

  6. 【SIKIA计划】_05_Unity5.3开发2D游戏笔记

    一.界面基本操作 01.Project基本分类[Audios]音效[Material]材质[Prefabs]预制[Scenes]场景[Scripts]脚本[Sprites]精灵 02.Project丶 ...

  7. java事务 深入Java事务的原理与应用

    一.什么是JAVA事务 通常的观念认为,事务仅与数据库相关. 事务必须服从ISO/IEC所制定的ACID原则.ACID是原子性(atomicity).一致性(consistency).隔离性 (iso ...

  8. 【Unity】 Cursor学习

    CursorLockMode.None 光标行为未修改,第一人称视角下鼠标可以突破窗口. CursorLockMode.Locked 光标锁定到游戏窗口的中心,与全屏与否无关,同时隐藏光标(这一点在3 ...

  9. jar包、war包

    JavaSE程序可以打包成Jar包(J其实可以理解为Java了),而JavaWeb程序可以打包成war包(w其实可以理解为Web了).然后把war发布到Tomcat的webapps目录下,Tomcat ...

  10. Android工程导入Unity3D(避坑版)

    最近与各种牛逼的项目管理软件打交道,比如SourceTree,要看英文版的才看得懂,中文反而不会用!... 这篇博客适合没怎么接触过安卓的小伙伴们,网上也有很多相关的教程,但是大多都没有具体的操作或则 ...