HDU4791_Alice's Print Service
全场最水题。
保留打印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的更多相关文章
- 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 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- 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 ...
- 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 ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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.. ...
随机推荐
- 正则表达式30min
如何使用本教程 正则表达式到底是什么东西? 入门 测试正则表达式 元字符 字符转义 重复 字符类 分枝条件 反义 分组 后向引用 零宽断言 负向零宽断言 注释 贪婪与懒惰 处理选项 平衡组/递归匹配 ...
- 开始试用Dynamics 365
1. 访问地址: https://trials.dynamics.com/Dynamics365/Signup/ ,默认选择第一个应用,也可以选择其他的,不影响,之后还可以添加更多的应用程序. 2. ...
- 模拟websocket推送消息服务mock工具二
模拟websocket推送消息服务mock工具二 在上一篇博文中有提到<使用electron开发一个h5的客户端应用创建http服务模拟后端接口mock>使用electron创建一个模拟后 ...
- 402. Remove K Digits/738.Monotone Increasing Digits/321. Create Maximum Number
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- 高可用OpenStack(Queen版)集群-13.分布式存储Ceph
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- maven 添加spring/springmvc依赖项
<spring.version>4.3.18.RELEASE</spring.version> <dependencies> <!--添加spring.spr ...
- Vs2012 编写代码规则
FxCop编写规则 VS2012 下更方便,所需的DLL在: D:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static ...
- ansible软件2
常用软件安装及使用目录 ansible使用1 第1章 copy模块 1.1 创建文件及写入内容 1. [root@m01 scripts]# ansible oldboy -m copy -a &q ...
- Xcode中的文件类型
文件类型 Xcode中的文件类型,总共4种类型: 1 普通文件(File) 2 Group(在Xcode中就是黄色的文件夹) 3 Folder(在Xcode中就是蓝色的文件夹) 4 Framework ...
- kafka启动报错:另一个程序正在使用此文件,进程无法访问。
在Windows上启动kafka_2.12-1.1.0报以下错误:[2018-05-08 10:24:51,777] ERROR Failed to clean up log for __consum ...