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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ 933 Bob's Print Service

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

Bob's Print Service

時(shí)間限制:1000?ms ?|? 內(nèi)存限制: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

題意:先給出兩個(gè)整數(shù)n、m,然后給出n個(gè)區(qū)間的臨界點(diǎn)和大于這個(gè)臨界點(diǎn)的每張紙的價(jià)格。然后給出m個(gè)k,問打印紙張數(shù)不低于k的最小花費(fèi)。

解題思路:先預(yù)處理一下,用一個(gè)數(shù)組v記錄處理后的結(jié)果,v[i]表示打印張數(shù)不低于臨界點(diǎn)s[i]時(shí)所花費(fèi)的最小的錢數(shù),然后二分查找出不低于要查找的紙張數(shù)的位置a,求出打印k張本該支付的錢數(shù)ans=k*p[a-1],將ans與記錄的v[a]比較,求出的最小值即為最小花費(fèi)。

#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;//二分查找,返回查找元素的最后一個(gè)可安插位置,即“元素值>查找值”的第一個(gè)元素的位置LL ans = k * p[a-1];if(a < n)ans = min(ans, v[a]);printf("%lld\n",ans);}}return 0; }

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。