A - Alice's Print Service

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money. 
For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per page. It's easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 × 10 cents instead of 99 × 20 cents. 
Now given the description of pricing strategy and some queries, your task is to figure out the best ways to complete those queries in order to save money.
 

Input

The first line contains an integer T (≈ 10) which is the number of test cases. Then T cases follow. 
Each case contains 3 lines. The first line contains two integers n, m (0 < n, m ≤ 10 5 ). The second line contains 2n integers s 1, p 1 , s 2, p2 , ..., s n, p n (0=s 1 < s 2 < ... < s n ≤ 10 9 , 10 9 ≥ p 1 ≥ p 2 ≥ ... ≥ p n ≥ 0).. The price when printing no less than s i but less than s i+1 pages is p i cents per page (for i=1..n-1). The price when printing no less than s n pages is p n cents per page. The third line containing m integers q 1 .. q m (0 ≤ q i ≤ 10 9 ) are the queries.
 

Output

For each query q i, you should output the minimum amount of money (in cents) to pay if you want to print q i pages, one output in one line.
 

Sample Input

1
2 3
0 20 100 10
0 99 100
 

Sample Output

0
1000
1000
 思路:稍微拿多一点可能更便宜
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define INF 1e18
using namespace std; const int maxn=100500; typedef long long LL; LL s[maxn],p[maxn],h[maxn]; int main()
{
int T,n,m;
LL mid,mmin,res;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
scanf("%I64d%I64d",&s[i],&p[i]);
h[i]=s[i]*p[i];
}
mmin=INF;
for(int i=n-1;i>=0;i--){
mmin=min(s[i]*p[i],mmin);
h[i]=mmin;
}
for(int kk=0;kk<m;kk++){
scanf("%I64d",&mid);
if(mid>=s[n-1]) printf("%I64d\n",mid*p[n-1]);
else{
int t=upper_bound(s,s+n,mid)-s;
res=mid*p[t-1];
res=min(res,h[t]);
printf("%I64d\n",res);
}
}
}
return 0;
}

  

HDU 4791 Alice's Print Service 思路,dp 难度:2的更多相关文章

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

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

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

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

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

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

  5. Alice's Print Service

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

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

  7. UVAlive 6611 Alice's Print Service 二分

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  8. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

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

  9. 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. 探索Java8:(二)Function接口的使用

    Java8 添加了一个新的特性Function,顾名思义这一定是一个函数式的操作.我们知道Java8的最大特性就是函数式接口.所有标注了@FunctionalInterface注解的接口都是函数式接口 ...

  2. [SpringBoot] - 一份笔记

    一. Spring Boot 入门 1. Spring Boot 简介 简化Spring应用开发的一个框架; 整个Spring技术栈的一个大整合; J2EE开发的一站式解决方案; 2. 微服务 201 ...

  3. spark-shuffle分析

    前言 shuffle是分布式计算系统中最重要的一部分,spark和mapreduce的shuffle的大体思路类似,在实现上有一些区分.Spark提供了插件式的接口,使用者可以通过继承ShuffleM ...

  4. [Err] 1111 - Invalid use of group function

    本文为博主原创,未经允许不得转载: 初衷,本想通过group by sql语句查询出不同id下总数在一定范围内的数据,所以产生如下的sql,及错误sql AND STATDATE < ' GRO ...

  5. java代码实现highchart与数据库数据结合完整案例分析(二)---折线图

    作者原创:未经博主允许不许转载 在上一篇的博客中,展示和分析了如何做一个饼状图,有疑问可以参考上一篇博客. 现在分析和展示折线图的绘制和案例分析, 先展示效果图: 与饼状图不同的是,折线图展现更多的数 ...

  6. The way to Go(3): 安装Go环境

    Reference: Github: Go Github: The way to Go 在mac上安装Go语言初体验 安装Go环境 Go 语言开发团队开发了适用于以下操作系统的编译器: Linux F ...

  7. kaggle CTR预估

    参考涛哥之前做过的CTR预估project,学习下CTR预估的相关知识:http://blog.csdn.net/hero_fantao/article/category/6877765 目标:本周末 ...

  8. Hibernate与iBastis 比较(转载)

    Hibernate  VS  iBATIS 简介 Hibernate 是当前最流行的O/R mapping框架,当前版本是3.05.它出身于sf.net,现在已经成为Jboss的一部分了 iBATIS ...

  9. Java 面向对象之static,final,匿名对象,内部类,包,修饰符

    01final关键字概念 A: 概述 继承的出现提高了代码的复用性,并方便开发.但随之也有问题,有些类在描述完之后,不想被继承, 或者有些类中的部分方法功能是固定的,不想让子类重写.可是当子类继承了这 ...

  10. bash 判断两个文件相等的代码

    #!/bin/bash #定义参数 username="xxx" passwd="xxxxxxxx" dbname="xxx" #判断入参为 ...