题目链接: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. sql总结一

    建表: select * from fruit; create table fruit ( id varchar(10) not null, name varchar(20) default '' n ...

  2. java编程思想-复用类总结

    今天继续读<java 编程思想>,读到了复用类一章,看到总结写的很好,现贴上来,给大家分享. 继承和组合都能从现有类型生成新类型.组合一般是将现有类型作为新类型底层实现的一部分来加以复用, ...

  3. webstorm9.3 安装less 编译css教程

    第一步:安装node.js webstrom9.3汉化下载:http://pan.baidu.com/s/1ntGNNiL    密码:1fbh node.js 下载地址:https://nodejs ...

  4. log4net 记录到数据库和本地文件

    1)配置代码 <?xml version="1.0" encoding="utf-8" ?> <configuration> <c ...

  5. spark 读取 elasticsearch数据

    –master spark://10.8.2.100:7077 –jars /usr/local/spark-1.5.2/lib/elasticsearch-hadoop-2.1.1.jar

  6. 入门:PHP:hello world!

    <?php echo 'hello'."\n"." world!"."good night!";//2016.09.18 22:57? ...

  7. CPU host-passthrough技术与应用

    为了保证虚拟机在不同宿主机之间迁移的时候的兼容性,Libvirt对CPU提炼出标准的几种类型,在/usr/share/libvirt/cpu_map.xml中可以查到.cpu_map.xml不仅是CP ...

  8. union联合体使用详解

    1.联合体联合体(union)与结构体(struct)有一些相似之处.但两者有本质上的不同.在结构体中,各成员有各自的内存空间, 一个结构变量的总长度是各成员长度之和.而在联合体中,各成员共享一段内存 ...

  9. createStatement()的用法

    createStatement()的用法 标签: 数据库concurrencyscrollsql 2012-02-24 19:58 2508人阅读 评论(0) 收藏 举报  分类: JavaEE服务器 ...

  10. C#通用类型转换 Convert.ChangeType

    ];         object innerValue = ChangeType(value, innerType);         return Activator.CreateInstance ...