NYOJ 933 Bob's Print Service
2013-11-24 17:33
246 查看
Bob's Print Service
时间限制:1000 ms | 内存限制:65535 KB难度:3
描述
Bob is providing print service,while the pricing doesn't seem to be reasonable,so people using her price service found some tricks to save money.
For example,the price when printing lwss than 100 pages is 20 cents per page,but when printing not less than 100 pages,you just need to pay only 10 cents 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.
输入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 S1,P1,S2,P2,……,Sn,Pn(0 = S1 < S2 < …… < Sn <= 10^9 ,
10^9 >= P1 >= P2 …… >= Pn >= 0).
The price when printing no less that S(i) but less that S(i+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 <= 10^9) are the queries.
输出For each query Qi,you should output the minimum amount of money(int cents) to pay if you want to print Qi pages, one output in one line.
样例输入
1 2 3 0 20 100 10 0 99 100
样例输出
0 1000 1000
题意:先给出两个整数n、m,然后给出n个区间的临界点和大于这个临界点的每张纸的价格。然后给出m个k,问打印纸张数不低于k的最小花费。
解题思路:先预处理一下,用一个数组v记录处理后的结果,v[i]表示打印张数不低于临界点s[i]时所花费的最小的钱数,然后二分查找出不低于要查找的纸张数的位置a,求出打印k张本该支付的钱数ans=k*p[a-1],将ans与记录的v[a]比较,求出的最小值即为最小花费。
#include<cstdio> #include<algorithm> using namespace std; typedef long long LL; const int N = 1e5 + 10; LL s , p , v ; int main() { int t, m, n, i, k; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i = 0; i < n; i++) scanf("%lld%lld",&s[i],&p[i]); for(i = n-1; i >= 0; i--) { if(i == n-1) v[i] = s[i] * p[i]; else v[i] = min(v[i+1], s[i] * p[i]); } while(m--) { scanf("%d",&k); int a = upper_bound(s, s+n, k) - s; //二分查找,返回查找元素的最后一个可安插位置,即“元素值>查找值”的第一个元素的位置 LL ans = k * p[a-1]; if(a < n) ans = min(ans, v[a]); printf("%lld\n",ans); } } return 0; }
相关文章推荐
- HDU 4791 Alice's Print Service
- hdu 4791 Alice's Print Service
- 2013长沙现场赛 Alice's Print Service
- zoj 3726& hdu 4791 Alice's Print Service
- HDU4791 Alice's Print Service
- ZOJ 3726 Alice's Print Service
- hdu 4791 Alice's Print Service (DP+离线处理)
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
- ZOJ 3726 Alice's Print Service
- HDU 4791 Alice's Print Service
- HDU 4791 Alice's Print Service
- hdu4791-Alice's Print Service(离线+暴力)
- ZOJ 3726 Alice's Print Service(RMQ)
- hdu4791 Alice's Print Service
- HDU - 4791 Alice's Print Service
- 系统找不到指定文件 No installed service name 'Apache2'
- 用户 'nt authority/network service' 登录失败
- tomcat7w.exe ,提示 指定的服务未安装 unable to open the service 'tomcat6'
- Failed installing 'Tomcat5' service