HDU 4791 Alice's Print Service 水二分
Alice's Print Service
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1084 Accepted Submission(s): 240
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.
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.
1
2 3
0 20 100 10
0 99 100
0
1000
1000
//484MS 2556K
#include<stdio.h>
#include<algorithm>
#define inf 1e13
using namespace std;
__int64 s[100007];
__int64 x[100007],y[100007];
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
__int64 mi;
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%I64d %I64d",&x[i],&y[i]);
for(int i=1;i<=n;i++)s[i]=x[i]*y[i];
s[n+1]=inf;
mi=s[n+1];
for(int i=n;i>=1;i--)
{
mi=min(s[i],mi);
s[i]=mi;
}
while(m--)
{
__int64 q,minn;
scanf("%I64d",&q);
int pos=lower_bound(x+1,x+n+1,q)-x;//在first和last中的前闭后开区间进行二分查找。返回大于或等于val的第一个元素位置。假设全部元素都小于val。则返回last的位置
minn=min(q*y[pos],s[pos+1]);
printf("%I64d\n",minn);
}
}
return 0;
}
HDU 4791 Alice's Print Service 水二分的更多相关文章
- 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 ...
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 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 4274 Spy's Work(水题)
Spy's Work Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 4122 Alice's mooncake shop (线段树)
题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ...
- HDU 5558 Alice's Classified Message(后缀数组+二分+rmq(+线段树?))
题意 大概就是给你一个串,对于每个\(i\),在\([1,i-1]\)中找到一个\(j\),使得\(lcp(i,j)\)最长,若有多个最大\(j\)选最小,求\(j\)和这个\(lcp\)长度 思路 ...
- 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 ...
- 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 ...
随机推荐
- 我的第一个ajax脚本
代码如下 //创建XMLHttpRequest对象 var xmlHttp=null; function creatXMLHttp(){ try{ xmlHttp = new XMLHttpReque ...
- 【07】像使用命令行一样使用 GitHub URL
[07] 像使用命令行一样使用 GitHub URL 既然说到了 URL,那么久接着聊一下.使用 UI 浏览 GitHub 很 方面也很好,不过很多时候最快的方式是使用 URL 来浏览.举个例子,如果 ...
- idea中代码费格式化 ctrl+alt+L
idea中代码费格式化 ctrl+alt+L
- 如何修改 WordPress 的默认 Gravatar 头像
如何修改 WordPress 的默认 Gravatar 头像? wordpress默认的头像是下面这种 在Settings的Discussion中,默认选择第一个Mystery Person, 意思是 ...
- POJ 2092 Grandpa is Famous
Grandpa is Famous Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 7153 Accepted: 3624 ...
- Python 打印嵌套list中每个数据(遍历列表)
new_list = ["H1","H2",1999] for each_list in new_list: print (each_list); 若列表中包含 ...
- 【bzoj3956】Count 单调栈+可持久化线段树
题目描述 输入 输出 样例输入 3 2 0 2 1 2 1 1 1 3 样例输出 0 3 题解 单调栈+可持久化线段树 本题是 bzoj4826 的弱化版(我为什么做题总喜欢先挑难的做QAQ) $k$ ...
- 北京集训TEST16——图片加密(fft+kmp)
题目: Description CJB天天要跟妹子聊天,可是他对微信的加密算法表示担心:“微信这种加密算法,早就过时了,我发明的加密算法早已风靡全球,安全性天下第一!” CJB是这样加密的:设CJB想 ...
- 洛谷 [P1436] 反素数
算术基本定理的应用 算术基本定理: 一个正整数 \(N\) 能唯一分解成如下形式 \[N=p_1 ^ {c_1}p_2^{c_2}\cdots P_m ^ {c_m}\] 其中 \(c_i\) 都是正 ...
- 清除svn检出导致的所有文件的问号
问题:将svn项目检出到桌面后,桌面的图标都有问号了,怎么消除这一大堆问号? 解决方案:(1)新建一个a.txt文件,把这行代码复制进去for /r . %%a in (.) do @if exist ...