HDU 4791 & zoj 3726 Alice's Print Service (Math Table)

Source: Internet
Author: User
Tags blank page

Question link:

HDU: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4791

Zju: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 5072


Problem descriptionalice 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. inputthe 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. outputfor each query Qi, you shocould output the minimum amount of money (in cents) to pay if you want to print Qi pages, one output in one line. sample Input
12 30 20 100 100 99 100
Sample output
010001000
Source2013 Asia Changsha Regional Contest


The HDU code is as follows:

# Include <cstdio> # include <cstdlib> # include <algorithm> # include <vector> # include <iostream> # define INF 1e18using namespace STD; const int maxn = 100017; typedef _ int64 ll; ll s [maxn], p [maxn], C [maxn]; int main () {int t; int n, m; ll tt; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); For (INT I = 0; I <n; I ++) {scanf ("% i64d % i64d", & S [I], & P [I]);} ll Minn = inf; for (INT I = n-1; I> = 0; I --) {Minn = min (s [I] * P [I], Minn ); c [I] = Minn ;}for (INT I = 0; I <m; I ++) {scanf ("% i64d", & TT ); if (tt> = s [n-1]) // final printf ("% i64d \ n", TT * P [n-1]); else {int Pos = upper_bound (S, S + N, TT)-S; ll ans = TT * P [pos-1]; ans = min (ANS, C [POS]); printf ("% i64d \ n ", ans) ;}}return 0 ;}


The zju code is as follows:

# Include <cstdio> # include <algorithm> # include <iostream> # define INF 1e18using namespace STD; const int maxn = 100017; typedef long ll; ll s [maxn], P [maxn], C [maxn]; int main () {int t; int n, m; ll tt; scanf ("% d", & T ); while (t --) {scanf ("% d", & N, & M); For (INT I = 0; I <n; I ++) {scanf ("% LLD", & S [I], & P [I]);} ll Minn = inf; For (INT I = n-1; i> = 0; I --) {Minn = min (s [I] * P [I], Minn); C [I] = Minn ;} for (INT I = 0; I <m; I ++) {scanf ("% LLD", & TT); If (tt> = s [n-1]) // finally printf ("% LLD \ n", TT * P [n-1]); else {int Pos = upper_bound (S, S + N, TT)-S; ll ans = TT * P [pos-1]; ans = min (ANS, C [POS]); printf ("% LLD \ n", ANS );}}} return 0 ;}


HDU 4791 & zoj 3726 Alice's Print Service (Math Table)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.