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.. ...
随机推荐
- Map.containsKey(String key)
判断key有没有对应的value值有,返回true无,返回false
- 流行创意风格教师求职简历免费word模板
18款流行创意风格教师求职简历免费word模板,也可用于其他专业和职业,个人免费简历模板,个人简历表免费,个人简历表格. 声明:该简历模板仅用于个人欣赏使用,请勿用于商业用途,谢谢. 下载地址:百度网 ...
- Ubuntu根目录下各文件夹的作用
Ubuntu上常识和常用命令: 1.Ubuntu文件结构 在ubuntu上硬盘的目录和Windows上不同,Windows可以根据自己的需求分不同的盘符,但ubuntu上只有一个盘,从根目录开始每个目 ...
- JMeter的__threadGroupName使用注意事项
JMeter从4.1版本开始引入了一个新函数"${__threadGroupName}",这个函数的作用是返回当前线程组的名字.${__threadGroupName}的用途也较为 ...
- Vue2.0原理-指令
指令是 模板解析 的续章,本文会尝试从源码的角度来理解 指令 是如何被提取和应用的. 指令的提取 指令的提取过程是在parse阶段进行的,在 parseHTML 方法中,会解析字符串模板为如下的单个a ...
- mnist手写数字识别(SVM)
import numpy as np from sklearn.neural_network import MLPClassifier from sklearn.linear_model import ...
- [操作系统]makefile
makefile文件保存了编译器和连接器的参数选项,还表述了所有源文件之间的关系(源代码文件需要的特定的包含文件,可执行文件要求包含的目标文件模块及库等). 创建程序(make程序)首先读取makef ...
- zabbix切换中文,监控图下方显示乱码,监控图X轴不显示时间问题解决(适用于所有版本)
一.现象: abbix3.4安装好后添加zabbix图形,发现有好多方块 这是因为zabbix web程序缺少中文字体 二.解决方案1: 1.在windows系统找一个中文字体上传到服务器中,我这里找 ...
- 【Python3.6】python打包成exe
D:\python_test>pip3 install pyinstaller…………D:\python_test>pyinstaller -F -w ui.py INFO: PyInst ...
- 2019第十届蓝桥杯C++B组题解(赛后重写的,不确保答案正确性,仅供参考)
先说一下这次的感受吧,我们考场比较乱,开始比赛了,还有的电脑有故障,(向这些人发出同情),第一次认真参加比赛,真正比赛的时候感觉没有那么正式,很乱,各种小问题,(例如博主就没找到题目在哪里,找到后又不 ...