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 ...
随机推荐
- 51nod 1489 蜥蜴和地下室(dp)
传送门 题意 分析 dp[12][20][20][20]; // dp[a][b][c][d]第a个弓箭手面临第a-1.a.a+1个弓箭手的生命值分别为b.c.d的状态 转移巧妙,需注意 trick ...
- 51nod 1268【dp】
思路: 很水的dp吧...问的都是能否组成.. 哦对,这里sum最大才2e7,不会是2e9所以放心dp #include<cstdio> #include <map> #inc ...
- hdu1085 Holding Bin-Laden Captive!【生成函数】
列出生成函数的多项式之后暴力乘即可 #include<iostream> #include<cstdio> #include<cstring> using name ...
- bzoj 3232: 圈地游戏【分数规划+最小割】
数组开小导致TTTTTLE-- 是分数规划,设sm为所有格子价值和,二分出mid之后,用最小割来判断,也就是判断sm-dinic()>=0 这个最小割比较像最大权闭合子图,建图是s像所有点连流量 ...
- Django使用dwebsocket来通信,服务器报错[Error 10038]
记录这次Django踩得最大的一次坑,没有之一.前前后后困扰了一周. 在使用Django的dwebsocket模块建立websocket时,不管是前端主动关闭,还是页面刷新,还是页面关闭.服务端均会报 ...
- 基于Tcp协议的上传下载
目录格式: 构建此目录就可随意使用! client端 import socket import sys import os import json import struct sk = socket. ...
- 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...
- VMware Workstation虚拟磁盘文件备份或移植
一.备份快照 1> 1.点击虚拟机上面的快速备份按钮 2.填写快照名字和备注 快照就生成了. 2>恢复 1.点击恢复按钮,此按钮的功能是直接恢复到上一次备份的节点. 2.或者选后面一个按钮 ...
- 释放资源的一般范式——更锋利的C#代码小记
public class Photo : IDisposable { //在Finalize函数中调用内部的Dispose方法 ~Photo() { //被自动回收时仅释放托管资源,不释放非托管资源 ...
- 微信小程序 图片加载失败处理方案
小程序端展示网络资源图片可能会失败,下面介绍一种自己的处理方法 1. js文件中判断图片 url 是否存在,存在则正常显示,不存在则替换url为本地默认图片 2. 当图片 url 存在,但是加载失败时 ...