A - Alice's Print Service ZOJ - 3726 (二分)
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 ≤ 105). The second line contains 2n integers s1, p1, s2, p2, ..., sn, pn (0=s1 < s2 < ... < sn ≤ 109, 109 ≥ p1 ≥ p2 ≥ ... ≥ pn ≥ 0). The price when printing no less than si but less than si+1 pages is pi cents per page (for i=1..n-1). The price when printing no less than sn pages is pn cents per page. The third line containing m integers q1 .. qm (0 ≤ qi ≤ 109) are the queries.
<h4< dd="">Output
For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.
<h4< dd="">Sample Input
1
2 3
0 20 100 10
0 99 100
<h4< dd="">Sample Output
0
1000
1000
题意:
就是说有一个人要打印东西,如果打印s页以上每张收费p元,让你求出来打印东西最少花钱多少。
但是要注意如果2页以上收a元,5页以上收b元,那么大于等于1小于5的时候才可以收a元每页,如果要是理解成1页到无穷多页都收费为a元,那就尴尬了(好像就是我)
然后就要注意的是,题目上说了s1<s2<....<sn,所以就不需要排序
具体看代码:
下面用到了关于二分的函数,不知道的话看链接:https://blog.csdn.net/qq_40160605/article/details/80150252
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=1e18+;
ll min(ll x,ll y)
{
return x>y ? y : x;
}
ll first[],second[],dp[];
int main()
{
ll t;
scanf("%lld",&t);
while(t--)
{
ll n,m,minn=INF;
memset(dp,,sizeof(dp));
scanf("%lld%lld",&n,&m);
for(ll i=;i<n;++i)
{
scanf("%lld%lld",&first[i],&second[i]);
minn=min(minn,second[i]);
}
dp[n]=INF;
for(ll i=n-;i>=;--i) dp[i]=min(dp[i+],second[i]*first[i]);
while(m--)
{
ll q;
scanf("%lld",&q);
if(q>=first[n-])
{
printf("%lld\n",q*second[n-]);
continue;
}
ll temp=upper_bound(first,first+n,q)-first;
ll ans=min(dp[temp],second[temp-]*q);
printf("%lld\n",ans);
}
}
return ;;
}
A - Alice's Print Service ZOJ - 3726 (二分)的更多相关文章
- 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 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 思路,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 ...
- 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.. ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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 ...
随机推荐
- SSM项目使用GoEasy 获取客户端上下线实时状态变化及在线客户列表
一.背景 上篇SSM项目使用GoEasy 实现web消息推送服务是GoEasy的一个用途,今天我们来看GoEasy的第二个用途:订阅客户端上下线实时状态变化.获取当前在线客户数量和在线客户列表.截止我 ...
- OO_第二单元总结
第二次总结博客(电梯单元) 16071070 陈泽寅 2019.4.20 一:多线程实验初感 这个单元是多线程设计的实践单元,主要让我们运用多线程的原理与思想去完成一个模拟电梯运行的策略.从最开始的单 ...
- Java中的String,StringBuilder,StringBuffer
String被final修饰,不可变,每次更改其实是重新创建了一个对象.StringBuilder,StringBuffer是可变的. StringBuffer是线程安全的,StringBuilder ...
- Appium环境搭建-精简版
Appium自动化环境准备 安装配置JDK 下载Android SDK并配置环境变量 安装模拟器或连接真机 安装appium desktop 安装python和pycharm (开发语言和开发工具) ...
- SQL SERVER2000将多行查询结果拼接到一行数据及函数的创建
处理前的查询结果如上图: 通过借助SQL变量的定义 ) DECLARE @Num int SET @Scope='' ), ' ' GROUP BY ContractID 实现了一下效果: //创建拼 ...
- [2019.04.01]Linux 学习心得(2)-- tar 命令的理解
这篇文章并不是发布最早的但是阅读量却每天都见长,很想知道各位大大是怎么找到这篇文章的.如果不忙,还请各位大大评论一下我看看,没准我可以为大家改进一下本文,提升一下质量. =============== ...
- Magento 2 自带模态的应用
Modal widget in Magento 2 Magento 2 自带模态的应用 使用magento 2 的自带模态组件,以下代码只供参考使用. 1,DOM >模态块与触发元素 .pthm ...
- django csrftoken
CSRF(跨站请求伪造) 背景知识:浏览器在发送请求的时候,会自动带上当前域名对应的cookie内容,发送给服务端,不管这个请求是来源A网站还是其它网站,只要请求的是A网站的链接,就会带上A网站的co ...
- python学习day19 面向对象(一)封装/多态/继承
面向对象 封装思想:将同一类的函数函数封装到同一个py文件中,方便调用 面向对象也有封装的作用,将同一类的函数封装到一个类中 多态(鸭子模型):多种类型/多种形态 #,什么事鸭子模型 对于一个函数,p ...
- 织梦dede如何获取图集调用第一张图片完美解决方法【5.7sp2版本】
制作产品图集多图效果的时候,常常需要获取图集第一张图片的功能,假设获取的是缩略图,那么缩略图不够大的情况下,第一展示效果就会很差,下面来介绍下如何获取调用织梦图集第一张图片的方法: 首先在 inclu ...