HDU 4791 Alice's Print Service 思路,dp 难度:2
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
Sample Input
2 3
0 20 100 10
0 99 100
Sample Output
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的更多相关文章
- 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 ...
- HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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 ...
- Alice's Print Service
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- 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 ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- 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 ...
随机推荐
- .Family_物联网
群名称 : .Family_物联网 QQ群号: 群介绍 基于嵌入式,构建各通信模式,网关,平台软件,工业系统等领域,欢迎各位朋友加群,交流学习!
- hdu 6180 Schedule
Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...
- [AtCoder ARC061F]Card Game for Three 组合数好题
题目链接 总结:组合数 这$F$题好难啊...只会部分分做法,下面两个方法都是部分分做法.满分做法我去看看...会的话就补一下 部分分做法 方法1: 首先$A$能赢的条件很明显,假设在所有的牌里面取出 ...
- 事务(Transaction)
1.演示转账的功能:(1)创建一张表示学生表表 CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(50), ac ...
- NS3 实验脚本的编写步骤
第一步:配置主机,安装模块 (1)创建N个节点: NodeContainer nodes; nodes.Creat(N); 比如我目前接触到的PointToPoint,N就是2 (2)利用拓扑助手He ...
- idea oracle反向工程生成实体类
1. 选择View-Tool Window- Database 2. 配置数据库信息 提示:配置完成后可以通过idea进行sql查询等操作 3.在项目中创建hbernate.cfg.xml文件, 在r ...
- 读jQuery源码有感
读之前的预备工作: 1.基础的js知识,以及html和css知识,和正则表达式知识.可以参考妙味课堂的基础js,html和css大纲. 2.JavaScript核心指南的知识http://www.cn ...
- Linux——系统引导流程学习简单笔记
开启电源: 固件 firmware(CMOS/BIOS) → POST 加电自检 对硬件就行检查 ↓ 自举程序 BootLoader(GRUB) → 载入内核 ↓ 载入内核 Kernel 1:驱动硬件 ...
- go 通道
1. package main import "fmt" func sum(s []int, c chan int) { sum := for _, v := range s { ...
- python 筛选
data=[,,,,,,,-,-] result=[x ]