HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791
解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询.
因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * px,要么多打印一点,多打印的时候可以确定打印的张数一定是x区间后面的某个区间的左端点的张数,因为已经超出我要打印的张数了,所以任意一个区间的中间的数量一定会大于这个区间的左端点的数量,所以,现在我要决定的就是打印多少张了,很显然,打印的张数要么是我现在输入的k张,要么是某个区间的左端点的值.但因为数据是10^5,所以我可以从后往前扫一遍,就可以确定这个可能导致费用最低的区间是哪个区间.然后就是确定k应该属于哪个区间的时候用二分查找就行了.
#include <cstdio>
#include <cstring>
#include<iostream>
#include <algorithm> using namespace std;
#define LL __int64//待会记得改
#define maxn 100010
struct node
{
LL tot,p;
LL s1,s2;
int next;
}all[maxn];
int find_s1(LL d,node* temp,int l,int r)
{
while(l < r)
{
int mid = (l + r) / ;
if(d <= temp[mid].s1) r = mid;
else if(d > temp[mid].s1) l = mid + ;
}
if(!(d >= temp[l].s1 && d < temp[l].s2)) return l-;
return l;
}
LL Min(LL a,LL b)
{
return a <= b? a:b;
}
LL Max(LL a,LL b)
{
return a >= b? a:b;
}
int main()
{
// freopen("in","r",stdin);
int T,n,m;
scanf("%d",&T);
LL d,s = ,t1,t2;
while(T--)
{
scanf("%d%d",&n,&m);
scanf("%I64d",&s);
for(int i = ;i < n-;++i)
{
scanf("%I64d%I64d",&all[i].p,&all[i].s2);
all[i].s1 = s;
all[i].tot = all[i].s1 * all[i].p;
s = all[i].s2;
}
all[n-].s1 = s;
all[n-].s2 = 0x7fffffff;
scanf("%I64d",&all[n-].p);
all[n-].tot = all[n-].p * all[n-].s1;
all[n-].next = n;
all[n] = all[n-];
int pp = n;
for(int i = n-;i >= ;--i)
{
all[i].next = pp;
if(all[pp].tot > all[i].tot) pp = i;
}
for(int i = ;i < m;++i)
{
scanf("%I64d",&d);
int q = find_s1(d,all,,n-);
t1 = all[q].p * d;
if(all[q].f != n-) //前n-1个
{
t2 = all[all[q].next].p * Max(all[all[q].next].s1,d);
printf("%I64d\n",Min(t1,t2));
}
else printf("%I64d\n",t1); //第n个的情况
}
}
return ;
}
HDU 4791 Alice's Print Service(2013长沙区域赛现场赛A题)的更多相关文章
- 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 思路,dp 难度:2
A - Alice's Print Service Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 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 ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- 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 ...
- 2011 ACM/ICPC 成都赛区(为2013/10/20成都现场赛Fighting)
hdu 4111 Alice and Bob 博弈:http://www.cnblogs.com/XDJjy/p/3350014.html hdu 4112 Break the Chocolate ...
- 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...
随机推荐
- group by语句
- centos忘记root密码,重新设置的方法
今天重新装了一个centos6.6,好像root密码没有叫我设置吧,然后用虚拟机开始安装之前的密码登录显示失败,所以有了下面的彩蛋.....Helloween... 在虚拟机安装了Centos,今天要 ...
- 通过命令行连接Wifi
前提:无线网卡驱动正常安装 1.检查连接无线的接口 $ iwconfig 一般无线接口为wlan0 2.检查无线接口是否工作 $ sudo ip link set wlan0 up 3.扫描周围无线网 ...
- 京东分布式MySQL集群方案介绍
背景 数据库作为一个非常基础的系统,任何一家互联网公司都会使用,数据库产品也很多,有Oracle.SQL Server .MySQL.PostgeSQL.MariaDB等,像SQLServer/Ora ...
- iOS开发-二维码
二维码 从ios7开始集成了二维码的生成和读取功能 此前被广泛使用的zbarsdk目前不支持64位处理器 生成二维码的步骤: 倒入CoreImage框架 通过滤镜CIFilter生成二维码 二维码的内 ...
- 最好的vim教程莫过于vimtutor
最好的vim教程莫过于vimtutor 直接运行vimtutor即可
- 基本药目录sop
http://db.yaozh.com/basicdir 基本药物 编辑 "基本药物"的概念, 由世界卫生组织于1977年提出,指的是能够满足基本医疗卫生需求,剂型适宜.保证供应. ...
- JavaScript学习笔记——对象分类
对象的分类 一.对象的分类 1.内置对象 Global Math 2.本地对象 Array Number String Boolean Function RegExp 3.宿主对象 DOM BOM 二 ...
- C#值类型参数传递的性能开销
Performance issues Let's dig a little deeper. When data is passed into methods as value type paramet ...
- Struts 中 ActionContext ctx.put()把数据放到ValueStack里之数据传输背后机制:ValueStack(值栈)
1. 数据传输背后机制:ValueStack(值栈) 在这一切的背后,是因为有了ValueStack(值栈)! ValueStack基础:OGNL要了解ValueStack,必须先理解OGNL ...