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.. ...
随机推荐
- Python值hashlib详解
一.hashlib的基本概念 .什么叫hash:hash是一种算法(不同的hash算法只是复杂度不一样)(.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SH ...
- 开箱即用 - log4net 日志
废话少说,先上代码 log4net Demo 好的系统都有日志,log4net 是我在.net平台下用过最爽的日志库,简单易用.功能强大. 基于配置(配置很简单,一看就明,通用,拷去即用): 可同时保 ...
- 读书笔记:《HTML5开发手册》--figure、time、details、mark
这是补充HTML5基础知识的系列内容,其他为: 一.HTML5-- 新的结构元素 二.HTML5-- figure.time.details.mark 三.HTML5-- details活学活用 四. ...
- axios的简单使用
axios是一个通用的ajax请求库,vue 2.0以后,推荐使用axios Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 使用: 1.下载安装 n ...
- Python对中文的支持
在Python中,经常会出现中文,出现中文有时候会报错,这时候很多新手在处理中文编码的时候会有点不知所措. Python主要有2.x和3.x版本两个区别,在3.x版本中,已经支持中文直接开发,而不需要 ...
- Stack Overflow访问问题的处理
一直以来都有访问stackoverflow的习惯,但是老是因为js的问题让人很多操作都操作不了,而且打开的速度也很慢. 原因其实就是stackoverflow使用的google的cdn,于是想彻底一点 ...
- sqli-labs学习笔记 DAY7
DAY7 sqli-labs阶段总结 基本步骤 判断是否报错 判断闭合符号 判断注入类型 构建payload 手工注入或者编写脚本 基本注入类型 报错型注入 floor公式(结果多出一个1):and ...
- Cocos2dx源码赏析(3)之事件分发
Cocos2dx源码赏析(3)之事件分发 这篇,继续从源码的角度赏析下Cocos2dx引擎的另一模块事件分发处理机制.引擎的版本是3.14.同时,也是学习总结的过程,希望通过这种方式来加深对Cocos ...
- Windows下 搭建redis集群
Windows下搭建redis集群教程 一,redis集群介绍 Redis cluster(redis集群)是在版本3.0后才支持的架构,和其他集群一样,都是为了解决单台服务器不够用的情况,也防止了主 ...
- plsql 不修改tnsnames.ora文件
PLSQL 不修改tnsname直接连数据库的方式在PLSQL的Database中直接输入192.168.1.6:1521/VP.其中192.168.1.6为数据库的IP:1521为数据库端口:VP为 ...