题目链接: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题)的更多相关文章

  1. 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 ...

  2. HDU 4791 Alice's Print Service 思路,dp 难度:2

    A - Alice's Print Service Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. HDU 4791 Alice&#39;s Print Service 水二分

    点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  4. 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 ...

  5. Alice's Print Service

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  6. UVAlive 6611 Alice's Print Service 二分

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...

  7. 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 ...

  8. 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 ...

  9. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

随机推荐

  1. 将maven工程转成dynamic web project

    http://blog.csdn.net/remote_roamer/article/details/51724378 做到最后一步就不行鸟,没有plugin........

  2. 关于vs生成app错误提示,提醒Execution failed for task ':transformClassesWithDexForDebug'.

    昨天将vs和android SDK更新之后生成app之后发现app生成出错,报错如下: FAILURE: Build failed with an exception. * What went wro ...

  3. springmvc 注解 配置文件解释

    概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...

  4. SQL Server 2012 启动

    1.  启动 SQL Server Management studio 2. 选择登录模式 Server name:   "." 代表本地的数据库 Authertication: ...

  5. vim 快捷键 以及技巧

    [root@centos01 biji]# vim + 1.txt 打开文件,光标定位到最后一行[root@centos01 biji]# vim +5 1.txt 打开文件,光标定位到第5行[roo ...

  6. Java——复选框:JCheckBox

    import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ItemEvent; import java. ...

  7. C#----对时间结构DateTime的使用(时间日期的使用)

    1.其初始化时间是0001--0--0 0:0:0 class Program { DateTime dt; static void Main(string[] args) { Program pp ...

  8. zepto.js之ajax剖析

    1.ajax的baseHeaders ajax插件中的baseHeaders对象的是http请求头部的信息 var mime = settings.accepts[dataType], baseHea ...

  9. 开源License

    http://www.open-open.com/bbs/view/1319816219625 http://my.oschina.net/yangsheng/blog/190917

  10. JS获取字符串实际长度(包含汉字)

    方法一: var jmz = {}; jmz.GetLength = function(str) { ///<summary>获得字符串实际长度,中文2,英文1</summary&g ...