2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)
Alice's Print Service
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 题意: 打印k页的资料,给出n中付费方案,一次打印超过s1但不超过s2的每页收费p1,超过s2不超过s3的收费p2.....数据保证0=s1<s2<...<sn,p1>=p1>=p3>=...>=pn。
接下来m个查询,对于每个查询问最少花多少钱?例如s1=0 s2=100 p1=20 p2=10 的时候,若要打印99页,显然直接打印100页要更便宜一点..所以结果是1000.. AC代码:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std; #define INF 0x7fffffff
#define maxn 100010
typedef unsigned long long ll; int n, m;
struct price
{
int s, p;
ll sum;
}a[maxn];
ll _min[maxn];
int BinarySearch(int x)
{
int l = , r = n;
int mid = l + (r-l)/;
while(l < r)
{
if(a[mid].s < x) {
if(a[mid+].s > x) return mid;
l = mid;
}
else if(a[mid].s > x) {
if(a[mid-].s <= x) return mid-;
r = mid;
}
else return mid;
mid = l + (r-l)/;
}
return l;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{ scanf("%d%d", &n, &m);
for(int i = ; i < n; i++){
scanf("%d%d", &a[i].s, &a[i].p);
a[i].sum = (ll)a[i].s * a[i].p;
}
_min[n-] = a[n-].sum;//注意此处的处理
for(int i = n-; i >= ; i--)
{
_min[i] = min(_min[i+], a[i].sum);
} while(m--)
{
int num;
ll ans = ;
scanf("%d", &num);
if(a[n-].s <= num)
printf("%lld\n", (ll)num*a[n-].p);
else
{
int pos = BinarySearch(num);
ans = (ll)num*a[pos].p;
ans = min(_min[pos+], ans);
printf("%lld\n", ans);
}
}
}
return ;
}
注意事项:
1、_min数组的存在:
很多人遗忘了这种情况:0 40;
10 30;
20 20;
40 4;
若要打印15份,最少情况其实可以使打印40份(可打空白页),花费160元。这就是考虑_min数组的必要性;
2、二分法查找pos:注意因为题意要求,所以会有些小不同;
2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)的更多相关文章
- 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)
Collision Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There's a round medal ...
- 2013 ACM/ICPC 长沙网络赛J题
题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...
- hdu 4435 第37届ACM/ICPC天津现场赛E题
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题目:给出N个城市,从1开始需要遍历所有点,选择一 ...
- 2013 ACM/ICPC 长春网络赛E题
题意:给出一个字符串,要从头.尾和中间找出三个完全相等的子串,这些串覆盖的区间互相不能有重叠部分.头.尾的串即为整个字符串的前缀和后缀.问这个相同的子串的最大长度是多少. 分析:利用KMP算法中的ne ...
- 2013 ACM/ICPC 长春网络赛F题
题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- 2013 ACM/ICPC 杭州网络赛C题
题意:驴和老虎,在一个矩阵的两个格子里,有各自的起始方向.两者以相同的速度向前移动,前方不能走时驴总是向右,老虎总是向左.他们不能超出矩阵边界也不能走自己走过的格子(但可以走对方走过的格子).如果不能 ...
- hdu 4432 第37届ACM/ICPC天津现场赛B题
题目大意就是找出n的约数,然后把约数在m进制下展开,各个数位的每一位平方求和,然后按m进制输出. 模拟即可 #include<cstdio> #include<iostream> ...
- HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题
第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...
随机推荐
- 解决JSP页面无法使用EasyUI里面class="easyui-dialog"的问题
当使用MyEclipse新建一个JSP页面的时候,MyEclipse会自动添加一些标记,这些标记也许不一定会在工程中使用到.比如<base href="<%=basePath%& ...
- 【原】Storm调度器
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Pluggable scheduler(可插拔调度器) Isolation schedu ...
- js基础第四天
多个tab栏切换class封装 <style> *{margin:0;padding:0;} ul{list-style:none;} .b ...
- 树-二叉平衡树AVL
基本概念 AVL树:树中任何节点的两个子树的高度最大差别为1. AVL树的查找.插入和删除在平均和最坏情况下都是O(logn). AVL实现 AVL树的节点包括的几个组成对象: (01) key -- ...
- STM32 串口DMA方式接收(转)
STM32 是一款基于ARM Cortex-M3内核的32位MCU,主频最高可达72M.最近因为要在车机上集成TPMS功能, 便开始着手STM32的开发工作,STM32F10x系列共有5个串口(USA ...
- IComparer接口与
IComparable比较接口,继承此接口可对lis<T>调用sort进行排序 或者调用sort时可以为sort方法提供继承了IComparer的比较器
- angularjs 中ie兼容性的问题收集
今天在项目中做ie8的兼容的时候,发现angularjs中一些内容这样写有问题,那样写就没有问题了,自己记录一下内容: 如果遇到了ie8中使用$http.post请求不到数据的时候,以下的方法是获取不 ...
- A Tour of Go Images
Package image defines the Image interface: package image type Image interface { ColorModel() color.M ...
- PT100测温电路经验
P100电压采集放大电路:前半部分是4.096V恒压源电路,然后是一个桥式电压采样电路,后面是一个电压放大电路. 一 4.096V恒压源电路: 因Vref = 2.5V,故有4.096 = (1 + ...
- unigui多页签UI框架
procedure TMainForm.openForm(Caption, FormClassName: string);var i: integer; sheet: TUniTabSheet;beg ...