分析:

1.由于价格是递减的,所以可能出现si*pi>sj*pj(j>i)。所以要有一个数组来储存当前端点的最小值。

2.然后二分查找当前的si,比较q*p[i]和M[i+1].不过在这之前要确认i是小于n的。】

3.upper_bound是返回第一个大于当前值得坐标,否则返回左闭右开的右端点。而lower_bound是返回第一个大于等于当前值得坐标。所以这里采用upper_bound。

 #include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
using namespace std;
#define M 100010
#define ll long long
ll s[M],p[M],q[M];
ll n,m;
ll best[M];
int main()
{
int T;
scanf("%d",&T);
for(int i=;i<T;i++)
{ scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%lld%lld",&s[i],&p[i]);
}
ll Min = s[n]*p[n];
best[n] = Min;
for(int i =n-;i>=;i--)
{
Min = min(Min,s[i]*p[i]);
best[i] = Min;
}
for(int i=;i<=m;i++)
{
scanf("%lld",&q[i]);
}
for(int i=;i<=m;i++)
{
if(q[i]>=s[n])
{
printf("%lld\n",q[i]*p[n]);
continue;
}
int t = upper_bound(s+,s++n,q[i])-s-;
printf("%lld\n",min(best[t+],q[i]*p[t]));
}
}
return ;
}

HDU-4791-Alice‘s Print Service的更多相关文章

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

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

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

  3. HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...

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

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

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

  6. Alice's Print Service

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

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

  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. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

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

随机推荐

  1. POJ - 1661 - Help Jimmy - 简单dp

    http://poj.org/problem?id=1661 一般化处理,把一开始的落地和大地都视作平台,设计平台类的属性.dp的时候显然是从上往下dp的,而且要小心Jimmy不能够穿过平台,也就是从 ...

  2. poj1724【最短路】

    题意: 给出n个城市,然后给出m条单向路,给出了每条路的距离和花费,问一个人有k coins,在不超过money的情况下从1到n最短路径路径. 思路: 我相信很多人在上面那道题的影响下,肯定会想想,在 ...

  3. 有哪些值得学习的spring boot开源项目?

    1. awesome-spring-boot 首先给大家介绍的就是Spring Boot 中文索引,这是一个专门收集 Spring Boot 相关资料的开源项目,也有对应的导航页面. 产品主页 htt ...

  4. Shell 根据名称杀掉进程

    代码如下: #!/bin/sh # 从命令行读取进程名称 NAME=$ echo "---------------" echo 'killing ->' $NAME # 过滤 ...

  5. C/C++预处理

    C/C++编译系统编译程序的过程为预处理.编译.链接.预处理器是在程序源文件被编译之前根据预处理指令对程序源文件进行处理的程序.预处理器指令以#号开头标识,末尾不包含分号.预处理命令不是C/C++语言 ...

  6. CSS实现文字旋转/实现角标

    主要用到属性transform:rotate(-30deg) example: .divedittable .project-tag div { width: 43px; line-height: 4 ...

  7. 在windows下编译出linux可执行程序

    set GOARCH=amd64 set GOOS=linux go build xx.go 会生成一个没有后缀的xx二进制文件 将该文件放入linux系统某个文件夹下 赋予权限 chmod 777 ...

  8. Python3 写入文件

    Demo: file = open("test.txt", "wb")file.write("string") 上面这段代码运行会报类型错误 ...

  9. 复位电路设计——利用PLL锁定信号(lock)产生复位信号

    利用PLL锁定信号(lock)产生复位信号 在FPGA刚上电的时候,系统所需的时钟一般都要经过PLL倍频,在时钟锁定(即稳定输出)以前,整个系统应处于复位状态.因此,我们可以利用PLL的锁定信号来产生 ...

  10. What is Scalability?

    Scalability is a system's ability to process more workload, with a proportional increase in system r ...