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 ...
随机推荐
- 线性表-串:KMP模式匹配算法
一.简单模式匹配算法(略,逐字符比较即可) 二.KMP模式匹配算法 next数组:j为字符序号,从1开始. (1)当j=1时,next=0: (2)当存在前缀=后缀情况,next=相同字符数+1: ( ...
- python 调试
python 调试基本和gdb调试一样,举例: debug .py #!/usr/bin/python print "hello" i=0 for j in range(10) ...
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
UVAlive 3983 Robotruck 题目: Robotruck Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format ...
- HW5.26
public class Solution { public static void main(String[] args) { int totalCount = 0; int lineCount = ...
- Android-Native-Server 启动和注册详细分析
Android-Native-Server 启动和注册详细分析 以mediaService为实例来讲解: mediaService的启动入口 是一个 传统的 main()函数 源码位置E:\ ...
- Android实例-解决虚拟键盘遮挡问题(XE8+小米2)
结果: 1.可以自动向上移动,来防遮挡,但同时发现个问题,如果是按硬件返回没有问题,要是点输入法(QQ.百度输入法)上的隐藏就不行了. 2.点击Edit2后出现输入法,点输入法上的隐藏后, 再点Edi ...
- 转载MSDN 在ASP.NET 中执行 URL 重写
转载文章原网址 http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 摘要:介绍如何使用 Microsoft ASP.NET 执行动态 URL 重 ...
- eclipse快捷键补充
编辑相关快捷键 注释 Ctrl + / 快速修复 Ctrl + 1 删除当前行 Ctrl + d 格式化文档 Ctrl + Shift + f 插入空行 Shift + ...
- (一)Bootstrap简介
Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的. Bootstrap优点: 移动设备优先:自 Boot ...
- flash Timer类使用
var timer:Timer = new Timer(1000); timer.addEventListener("timer",tracerTimer); function t ...