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 ...
随机推荐
- JavaWeb---总结(十四)JSP原理
一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...
- Java-IO之DeflaterOutputStream和InflaterOutputStream
此类为使用 "deflate" 压缩格式压缩数据实现输出流过滤器 example import java.io.File; import java.io.FileInputStre ...
- DllImport dll中有些啥函数 及 dll中是否用到了别的dll
在加载dll的时候不知道dll中有哪些接口怎么办,或者使用别人封装的东西时报出类似于“无法在 DLL“XXX.dll”中找到名为“XXX函数”的入口点.” 1.通过LordPE这个软件来看dl ...
- nginx重定向配置
# /etc/nginx/nginx.conf #写在server,location核心模块中,if也可以写.$http_host客户端设法要到达主机的主机名 if ($http_host !~ “^ ...
- ecshop 影响全局的标量lib_main.php
lib_mian.php 前台公用函数库 1.增加自定义变量 "版权所属" $copyright 或者 $smarty->assign('get_article_ ...
- C-基本语法与运算
编译: Technorati 标记: C 1, 编译compilers 命令make 将高级语言转换为低级语言. clang: 1,预处理(preprocessing) 2,编译(complition ...
- [转]Sql按年份.月份.每天统计数量
1.每年 select year(ordertime) 年, sum(Total) 合计 from 表 group by year(ordertime) 2.每月 select year(ordert ...
- tmux常用命令
tmux命令可以启动一个tmux服务,tmux服务包含多个session,session包含多个window,window包含多个pane. 常用命令tmux ls #显示已有tmux列表(C-b s ...
- Double和double的区别
1.Double是java定义的类,而double是预定义数据类型(8种中的一种)2.Double就好比是对double类型的封装,内置很多方法可以实现String到double的转换,以及获取各种d ...
- linux中Jetty的安装和配置
Jetty Jetty 是一个开源的servlet容器,它为基于Java的web内容,例如JSP和servlet提供运行环境.Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布.开 ...