HDU 4791 amp; ZOJ 3726 Alice#39;s Print Service (數學 打表)

題目鏈接:

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072


Problem Description
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.
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.
Sample Input
1 2 3 0 20 100 10 0 99 100
Sample Output
0 1000 1000
Source
2013 Asia Changsha Regional Contest


題意:

打印紙張,隨著張數的添加,每張的價格非遞增,給出 m 個詢問打印的張數,求出最小的花費。

PS:

保留打印a[i]份分別須要的錢,從后往前掃一遍,保證取得最優解。

然后再找到所打印的張數的區間,與沒有多打印,僅僅打印m張所需的花費比較!


HDU代碼例如以下:

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define INF 1e18
using 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%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])//最后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;
}


ZJU代碼例如以下:

#include <cstdio>
#include <algorithm>
#include <iostream>
#define INF 1e18
using namespace std;const int maxn = 100017;
typedef long 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%d",&n,&m);for(int i = 0; i < n; i++){scanf("%lld%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])//最后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;
}


轉載于:https://www.cnblogs.com/mengfanrong/p/4292488.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375297.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375297.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375297.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

奪命雷公狗---ECSHOP---08---商品頁的拇改成星星

<strong>用戶評價&#xff1a;</strong>{*---------商品評價星星開始----------*}<img src"./images/stars{$goods.comment_rank}.gif" alt"comment rank {$goods.comment_rank}">{*---------商品評價星星結束-------*} 這里主要是要有星…

文件指針

一.移動文件指針 SetFilePointer,hFile,lDistanceToMove,lpDistanceToMoveHigh,dwMoveMethod dwMoveMethod 指明移動的模式 FILE_BEGIN 不管文件處于什么地方,總是從文件的頭部開始移動,這時的位置參數相當于指定了一個絕對位置 FILE_CURRENT 從當前的文件指針處開始移…

見證下的自我變化-2014全年總結

又是一年總結季&#xff0c;回過頭看看看自己的成長&#xff0c;心里真的是滿滿的喜悅之情…… 一年前自己的總結博客&#xff1a;http://blog.csdn.net/huo065000/article/details/19632603 半年前自己的總結博客&#xff1a;http://blog.csdn.net/huo065000/article/details/…

【Linux學習篇】This virtual machine is configured for 64-bit guest operating systems.……

在學習Linux的基本操作的時候&#xff0c;安裝虛擬環境則提示自己 This virtualmachine is configured for 64-bit guest operatingsystems.……起初由于各種拒絕的心理&#xff0c;所以屏蔽了這個錯誤&#xff0c;但是屏蔽永遠也解決不了問題的&#xff0c;所以自己則嘗試百度…

圖解SSIS監視文件夾并自動導入數據

圖解SSIS監視文件夾并自動導入數據 原文:圖解SSIS監視文件夾并自動導入數據 演示案例&#xff1a;讓系統自動監視文件夾&#xff0c;并把文件夾下面的excel文件導入到sql中&#xff0c;之后清空目錄。這個過程以往都需要寫程序來實現或者定時執行&#xff0c;現在可以用ssis來訂…

DLL轉Lib

在C中,為了允許操作符重載和函數重載,C編譯器往往按照某種規則改寫每一個入口點的符號名,以便使用同一個名字(具有不同的參數類型或者是不同的作用域)有多種不同的用法,而不會打破現有基于C的鏈接器,.這項技術通常被稱為改編(Name Mangling)或者名稱修飾(Name Decoration),許多…

WP8手機解鎖時提示“請確保IPOVERUSBSVC服務正常運行”解決方法

如果你各種重啟服務 卸載手機 重裝驅動都試過了還不行&#xff0c;請看看你是否安裝了Hyper-v或Vitualbox虛擬機&#xff0c;很有可能是虛擬交換機造成的。 我在網絡連接屬性里看到這個 把它卸載后&#xff0c;解鎖成功。 解鎖后記得重新安裝卸載的那個網絡服務轉載于:https://…

Win32路徑操作相關API

一.路徑截斷與合并 PathRemoveArgs 去除路徑的參數 PathRemoveBackslash 去除路徑最后的反斜杠 "\" PathAddBackslash 在路徑最后加上反斜杠 "\" PathRemoveBlanks 去除路徑前后的空格 PathAddExtension 在文件路徑后面加上擴展名 PathRemoveExtension 去…

Openjudge-計算概論(A)-稱體重

描述&#xff1a; 趙、錢、孫、李四個人中既有大人也有小孩&#xff0c;給他們稱體重時發現&#xff0c;他們每個人的體重都不一樣&#xff0c;且體重&#xff08;單位&#xff1a;公斤&#xff09;恰好是10的整數倍&#xff0c;且他們的體重都不高 于50公斤&#xff0c;已知趙…

浮點數的存儲

-------------------------------------------------------------------------------- 在VC6.0----float環境一共32位 其中第一位是符號位 第二到第9位中間8位為小數點位置&#xff08;指數以127的二進制為原點向下為負指數 向上為正指數&#xff09;后面23位為數據位。 S EE…

第二階段總結

結合第二階段后3天&#xff0c;我們試用了UI&#xff0c;antionbar&#xff0c;menu等實用&#xff0c;成功的做出了字體的轉換&#xff0c;題目的轉化等功能。 其實四則運算&#xff0c;說難不難 說易不易&#xff0c;總結出 主要有付出&#xff0c;就有回報。 menu等做的過程…

const 和指針

c用了那么久&#xff0c;覺得 const 和指針配合到一起的時候就會有點點分不出來。 如下: const Data* pData;Data const * pDataData * const pDataconst Data * const pData Data const * const pData是不是有點暈&#xff1f; 我其實用得最多的是 const Data* pData, 也…

Linux 查看系統用戶的登錄日志

查看用戶登錄系統的日志有兩類日志記錄用戶登錄的行為&#xff0c;一是記錄登錄者的數據&#xff0c;一個是記錄用戶的登錄時間一&#xff0c;記錄用戶登錄數據/var/log/wtmp日志文件記錄用戶登錄的數據。但這個文件是被編碼的文件&#xff0c;不能直接用vi、cat等命令查看&…

Android -- 自定義權限

在android系統的安全模型中&#xff0c;應用程序在默認的情況下不可以執行任何對其他應用程序&#xff0c;系統或者用戶帶來負面影響的操作。如果應用需要執行某些操作&#xff0c;就需要聲明使用這個操作對應的權限。 &#xff08;在manifest文件中 添加標記&#xff09;。 ap…

Win32 路徑操作API

路徑操作相關API 路徑截斷與合并函數 PathRemoveArgs 去除路徑的參數 PathRemoveBackslash 去除路徑最后的反斜杠“\” PathAddBackslash 在路徑最后加上反斜杠“\” PathRemoveBlanks 去除路徑前后的空格 PathAddExtension 在文件路徑后面加上擴展名 Pa…

dbms_output.put_line長度限制問題

dbms_output.put_line長度限制問題對于10g以上版本(包括10g), dbms_output.put_line的最大長度限制是32767. 如果報錯buffer overflow, 執行如下語句即可:set serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED對于10g以下版本dbms_output.put_line最大長度限制是255.轉載于…

js深入研究之Person類案例

<script type"text/javascript"> /* 定義一個Person類 */ function Person(name, age) {this.name name;this.age age; } /* 添加兩個方法getName getAge */ Person.prototype {getName: function() {return this.name;},getAge: function() {return this.a…

C++名稱粉碎

C name mangling 1: ?0: 構造器&#xff0c;?1 析構器 2: QAE: public __thiscall AAE: private __thiscall QBE: public __thiscall const 3: 返回值和參數類型 B&#xff1a;const D&#xff1a;char E&#xff1a;unsigned char F&#xff1a;…

一款基于css3鼠標經過圓形旋轉特效

今天給大家分享一款基于css3鼠標經過圓形旋轉特效。當鼠標經過的時候圖片邊框顏色旋轉&#xff0c;圖片顯示詳情。該實例適用瀏覽器&#xff1a;IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗。效果圖如下&#xff1a; 在線預覽 源碼下載 實現的代碼。 ht…

Delphi與Windows 7下的用戶賬戶控制(UAC)機制

WIN7/WIN8/WIN10, Vista提供的UAC機制&#xff0c;它的主要目的是防止對于操作系統本身的惡意修改。 對于Delphi程序的影響&#xff0c;UAC主要在于以下幾點&#xff1a; 1、由于UAC機制&#xff0c;Delphi對于系統的操作可能無聲的失敗&#xff0c;而同樣的程序&#xff0c;在…