日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ 933 Bob's Print Service

發布時間:2025/3/16 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ 933 Bob's Print Service 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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[N], p[N], v[N]; 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];elsev[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; }

總結

以上是生活随笔為你收集整理的NYOJ 933 Bob's Print Service的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。