HDU-4791-Alice‘s Print Service
分析:
1.由于价格是递减的,所以可能出现si*pi>sj*pj(j>i)。所以要有一个数组来储存当前端点的最小值。
2.然后二分查找当前的si,比较q*p[i]和M[i+1].不过在这之前要确认i是小于n的。】
3.upper_bound是返回第一个大于当前值得坐标,否则返回左闭右开的右端点。而lower_bound是返回第一个大于等于当前值得坐标。所以这里采用upper_bound。
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
using namespace std;
#define M 100010
#define ll long long
ll s[M],p[M],q[M];
ll n,m;
ll best[M];
int main()
{
int T;
scanf("%d",&T);
for(int i=;i<T;i++)
{ scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%lld%lld",&s[i],&p[i]);
}
ll Min = s[n]*p[n];
best[n] = Min;
for(int i =n-;i>=;i--)
{
Min = min(Min,s[i]*p[i]);
best[i] = Min;
}
for(int i=;i<=m;i++)
{
scanf("%lld",&q[i]);
}
for(int i=;i<=m;i++)
{
if(q[i]>=s[n])
{
printf("%lld\n",q[i]*p[n]);
continue;
}
int t = upper_bound(s+,s++n,q[i])-s-;
printf("%lld\n",min(best[t+],q[i]*p[t]));
}
}
return ;
}
HDU-4791-Alice‘s Print Service的更多相关文章
- HDU 4791 Alice's Print Service 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 4791 Alice's Print Service (2013长沙现场赛,二分)
Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3.. ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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 ser ...
- Alice's Print Service
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- A - Alice's Print Service ZOJ - 3726 (二分)
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
随机推荐
- (水题)Codeforces - 650A - Watchmen
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...
- Codeforces 702B【二分】
题意: 给一个a数组,输出有多少对相加是等于2^x的.1<=a[i]<=1e9,n<=1e5 思路: a[i]+a[j]=2^x 对于每个a[i],枚举x,然后二分查找a[j]; p ...
- update cdh version ,but cdh use old conf ,problem solve
最近升级cdh版本,从4.5 升级到 5.0.0 beta-2 但是升级后,发现/etc/alternatives 路径下的软链接还是只想旧的4.5 版本,而且hadoop环境也是沿用4.5 的版本c ...
- Luogu P1663 山【二分答案/实数域】By cellur925
题目传送门 现在要在山上的某个部位装一盏灯,使得这座山的任何一个部位都能够被看到. 给出最小的y坐标,如图的+号处就是y坐标最小的安装灯的地方. 这个题嘛...今年省选前学姐来我们(破烂)的机房串门的 ...
- c++ 语法解析
大小 size()是取字符串长度的,跟length()用法相同 size_t其实是一种类型,类似于无符号整形(unsignted int).可以理解成unsignted int size,当unsig ...
- Android课程设计第五天欢迎界面(滑动)和图形选择
注意:课程设计只为完成任务,不做细节描述~ 滑动界面 package com.example.myapplication; import android.content.Intent; import ...
- 1-13Object类之toString方法
Object中的toString方法 SUN在Object类中设计toString方法的目的:返回java对象的字符串表示形式. 在现实的开发过程中,Object中的toString方法就是要被重写的 ...
- httpclient 3.1跳过https请求SSL的验证
一.因为在使用https发送请求的时候会涉及,验证方式.但是这种方式在使用的时候很不方便.特别是在请求外部接口的时候,所以这我写了一个跳过验证的方式.(供参考) 二.加入包,这里用的是commons- ...
- PHP的知识点总结1
PHP 基础知识总结 2015-06-03 分类: 编程技术 PHP 代表 PHP: Hypertext Preprocessor PHP 文件可包含文本.HTML.JavaScript代码和 P ...
- 利用伪类写一个自定义checkbox和radio
首先是效果图来一张 再来一张html结构 关键的CSS来了~ 首先呢要把input标签设置为display: none; 因为自定义的原理是通过label的for属性,来点击label转向为点击in ...