分析:

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. 洛谷 - P2945 - 沙堡Sand Castle - 排序

    https://www.luogu.org/problemnew/show/P2945 好像猜一猜就觉得排序之后是最优的,懒得证明了.每个城墙向他最接近的城墙靠近,绝对是最优的.

  2. 洛谷 - P1004 - 方格取数 - 简单dp

    https://www.luogu.org/problemnew/show/P1004 这道题分类到简单dp但是感觉一点都不简单……这种做两次的dp真的不是很懂怎么写.假如是贪心做两次,感觉又不能证明 ...

  3. Educational Codeforces Round 21E selling souvenirs (dp)

    传送门 题意 给出n个体积为wi,价值为ci的物品,现在有一个m大的背包 问如何装使得最后背包内的物品价值最大,输出价值 分析 一般的思路是01背包,但n*v不可做 题解的思路 We can iter ...

  4. poj2421【MST-prim+Kruskal】

    水过~~~~打好基础/~~ ------prim #include <iostream> #include <stdio.h> #include <string.h> ...

  5. bzoj 4551: [Tjoi2016&Heoi2016]树【并查集】

    看起来像是并查集,但是是拆集合,考虑时间倒流,先把标记都打上,然后把并查集做出来 每次到一个修改点就把这个点的计数s[u]--,当这个s为0时就把这个点和他的父亲合并(因为可能有多次标记) #incl ...

  6. 【Tip】JavaScript

    『JavaScript』 『引用网络资源』 JQuery <script src="http://code.jquery.com/jquery-latest.js">& ...

  7. $ybt\ 【信息学奥赛一本通】题解目录$

    [信息学奥赛一本通]题解目录 $ \large -> OJ$ $ problem1000 $ \(Answer\) - > $ \large 1000$ $ problem1001 $ \ ...

  8. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解

    真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...

  9. windows session 管理

    Killing an Oracle process from inside Oracle I had a following situation few days ago – I was runnin ...

  10. LVS集群-DR模式

    同上个实验一样,还是准备三台机器 分发器(sishen_63):eth0 192.168.1.63 RealServer1sishen_64) RealServer2sishen_65) 首先配置网卡 ...