A - Alice's Print Service ZOJ - 3726 (二分)
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money.
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.
Input
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 ≤ 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.
<h4< dd="">Output
For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.
<h4< dd="">Sample Input
1 2 3 0 20 100 10 0 99 100
<h4< dd="">Sample Output
0 1000 1000
题意:
就是说有一个人要打印东西,如果打印s页以上每张收费p元,让你求出来打印东西最少花钱多少。
但是要注意如果2页以上收a元,5页以上收b元,那么大于等于1小于5的时候才可以收a元每页,如果要是理解成1页到无穷多页都收费为a元,那就尴尬了(好像就是我)
然后就要注意的是,题目上说了s1<s2<....<sn,所以就不需要排序
具体看代码:
下面用到了关于二分的函数,不知道的话看链接:https://blog.csdn.net/qq_40160605/article/details/80150252
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const ll INF=1e18+5; ll min(ll x,ll y) { return x>y ? y : x; } ll first[100005],second[100005],dp[100005]; int main() { ll t; scanf("%lld",&t); while(t--) { ll n,m,minn=INF; memset(dp,0,sizeof(dp)); scanf("%lld%lld",&n,&m); for(ll i=0;i<n;++i) { scanf("%lld%lld",&first[i],&second[i]); minn=min(minn,second[i]); } dp[n]=INF; for(ll i=n-1;i>=0;--i) dp[i]=min(dp[i+1],second[i]*first[i]); while(m--) { ll q; scanf("%lld",&q); if(q>=first[n-1]) { printf("%lld\n",q*second[n-1]); continue; } ll temp=upper_bound(first,first+n,q)-first; ll ans=min(dp[temp],second[temp-1]*q); printf("%lld\n",ans); } } return 0;; }
相关文章
- GZIP in .net core not working Unable to resolve service for type 'Microsoft.AspNetCore.ResponseCompression.IResponseCompressionProvider'
- cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
- IIS Manager could not load type for module provider 'SharedConfig' that is declared in administration.config
- Could not load file or assembly 'System.Web.Http Fuslogvw.exe (Assembly Binding Log Viewer)
- 报错:Flink Could not find a file system implementation for scheme 'hdfs'
- 【POJ3683】Priest John's Busiest Day
- 【CF718E】Matvey's Birthday BFS+动态规划
- python 'libinstall' failed [libinstall] Error 1 解决办法
- Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
- Avoid using implementation types like 'HashMap'; use the interface instead
- HDU 3966 Aragorn's Story (简单树链剖分)
- SAP MM VL32N和MIGO对内向交货单做收货,都会更新其'总体货物移动状态'
- if you are not making someone else's life better, then you are wasting your time.– Will Smith如果你不能给别人的生活带来改善,那么你就是在浪费你的宝贵时间。 --威尔 史密斯(程序员,你做的东西...)
- org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;bounda
- 转 MySQL shell脚本执行错误 $'r':command not found
- mariadb启动报错:[ERROR] Can't start server : Bind on unix socket: Permission denied
- SSH 出现 The authenticity of host xxx can't be established.
- mysql 1093 - You can't specify target table 'xx表' for update in FROM clause
- angularjs 1 Failed to read the 'selectionStart' property from 'HTMLInputElement':
- Windows解决多版本python执行pip3时出错AttributeError: module 'enum' has no attribute 'IntFlag'?
- xtrabackup备份失败(error writing file 'UNOPENED')
- node 中 npm报错 Error: ENOENT, stat 'C:UsersAdministratorAppDataRoamingnpm'
- TypeError: 'module' object is not callable(“模块”对象不可调用)