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)function creatXMLHttpRequest(){ try{ return new XMLHttpRequest(); } catch(e){ t ...
- LeetCode(153) Find Minimum in Rotated Sorted Array
题目 Total Accepted: 65121 Total Submissions: 190974 Difficulty: Medium Suppose a sorted array is rota ...
- MPEG-4视频编码核心思想
1 引言 当今时代,信息技术和计算机互联网飞速发展,在此背景下,多媒体信息已成为人类获取信息的最主要载体,同时也成为电子信息领域技术开发和研究的热点.多媒体信息经数字化处理后具有易于加密.抗干扰能 ...
- Debian 修改时间时区
http://blog.51cto.com/zhujiangtao/1554976 第一种图形化方面推荐使用 第二种修改文件的形式 只是在当前的terminal生效 笔者使用的是: debian9.3
- 解决手机助手与 android sdk 的adb 冲突问题
现象:手机助手与 sdk 内的 adb冲突,用助手与真机连接后,sdk adb 就被干掉了 突发奇想: 突然有一天想到用助手的adb来覆盖sdk内的adb,果然奏效.现在eclipse.助手.cmd窗 ...
- iphone丢了以后发现关机了怎么办?
有好几个办法都可以尝试一下: 1. "ICCID法",但目前这个办法只能寻找苹果iPhone手机,而对于安卓手机,则不能采取相同的方法进行寻找.之所以能采取该方法寻找苹果 iPho ...
- mysql数据库修改字段类型
修改字段类型: alter table 表名 modify column 字段名字 decimal(18, 4) ;
- Percona XtraBackup 2.4新特性之恢复单个表数据
参考文档:https://www.percona.com/doc/percona-xtrabackup/2.4/xtrabackup_bin/restoring_individual_tables.h ...
- 算法复习——欧拉函数(poj3090)
题目: Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or e ...
- CodeForces 303B Rectangle Puzzle II
题意: 给定一个靠着坐标轴长为n,宽为m的矩形和 矩形中的一个点A,求在这个矩形内部一个 长宽比为a/b的小矩形,使这个小矩形的长宽尽量大使点A在小矩形内部,并且点A尽量靠近小矩形的中心 CF的思维题 ...