ZOJ 3726 RMQ + 二分法
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072
区域赛真干的话题
通过率最高的一个问题 不到一半认为这OK 然后WA果断地 另外int无用long long WA
好久没用RMQ 调试也花了一点时间,
upper——bound返回的是大于x的第一个数的下标,最大当然是返回end的位置,注意推断下
注意一点,如果须要打印的张数为x s[i]=<x<s[i+1] 事实上 要找的是ans=min(p[i]*x,s[i+1]*p[i+1],s[i+1]*p[i+2]...s[n]*p[n]),所以单单二分必定不行啊
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath> using namespace std; const int MAXN = 1e5+100;
#define IN(s) freopen(s,"r",stdin)
#define ll long long
#define ull unsigned long long
const ll INF = ((ull)(-1))>>1;
ll s[MAXN],p[MAXN],tot[MAXN];
int n,m;
ll d[20];
ll st[MAXN][20];
void init()
{
for(int i=0;i<n;i++)st[i][0]=tot[i+1];
int k = (int)( log(double(n*1.0)/log(2.0)) ) +1;
for(int j=1;j<k;j++)
for(int i=0;i<n;i++)
{
if(i + d[j-1]-1 <n)
{
st[i][j] = min( st[i][j-1], st[i+d[j-1]][j-1] );
}
else break;
}
} void query(int q)
{
int y=n-1;
for(int i=0;i<q;i++)
{
int x,k;
scanf("%d",&x);
int id= upper_bound(s+1,s+1+n,x)-(s+1);
if(id>=n)
{
printf("%lld\n",p[n]*x);
continue;
}
ll ans=INF;
ans=min(ans,p[id]*x);
k=int( log(double(y-id+1)/log(2.0)) );
ans=min(ans,min(st[id][k],st[y-d[k]+1][k]));
printf("%lld\n",ans);
}
} int main()
{
//IN("zoj3726.txt");
d[0]=1;
for(int i=1;i<21;i++)d[i]=2*d[i-1];
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&s[i],&p[i]);
tot[i]=s[i]*p[i];
}
init();
query(m);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
ZOJ 3726 RMQ + 二分法的更多相关文章
- 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 ...
- Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, w ...
- zoj 3665 数论 二分法 两个参数
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4888 标题两个参数,途径:小参数的枚举,然后二分法大参数 想想两个点.以后就不 ...
- I - Beautiful People ZOJ - 2319 (二分法)
The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...
- 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 ...
- 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 ...
- 近几年ACM/ICPC区域赛铜牌题
2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...
- ZOJ Design the city LCA转RMQ
Design the city Time Limit: 1 Second Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...
- ZOJ 3195 Design the city LCA转RMQ
题意:给定n个点,下面n-1行 u , v ,dis 表示一条无向边和边权值,这里给了一颗无向树 下面m表示m个询问,问 u v n 三点最短距离 典型的LCA转RMQ #include<std ...
随机推荐
- [Recompose] Show a Spinner While a Component is Loading using Recompose
Learn how to use the 'branch' and 'renderComponent' higher-order components to show a spinner while ...
- javascript中定义事件的三种方式 分类: C1_HTML/JS/JQUERY 2014-08-07 10:27 634人阅读 评论(0) 收藏
在javascript中,可以为某个元素指定事件,指定的方式有以下三种: 1.在html中,使用onclick属性 2.在javascript中,使用onclick属性 3.在javascipt中,使 ...
- POI操作Excel常用方法总结 分类: B1_JAVA 2013-08-23 10:01 349人阅读 评论(0) 收藏
转载自:http://blog.csdn.net/xjun15/article/details/5805429 一. POI简介 Apache POI是Apache ...
- thinkphp5项目--练手--企业单车网站(九)(友情链接)
thinkphp5项目--练手--企业单车网站(九)(友情链接) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Webs ...
- Android 输入框弹出样式
在androidMainfest.xml文件里 在Activity中设置 [A]stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置 [B]stateU ...
- android Navigator的高度计算和推断是否显示
进入互联网行业几天了, 从手机行业转到互联网行业也在慢慢的适应: IDE工具的使用(之前一直在Ubuntu 命令行进行开发). 版本号管理工具,代码架构等等这些都须要又一次适应. 好在本人另一些底子, ...
- web项目开启日志打印
原文链接:http://blog.csdn.net/qq_37936542/article/details/79045188 参考文章地址:点击打开链接,写的很清晰 一:导入log4j包或依赖 ...
- wait()、notify()、notifyAll()与线程通信方式总结
1.通过wait().notify().notifyAll()进行线程通信 线程通信的目标是使线程间能够互相发送信号.另一方面,线程通信使线程能够等待其他线程的信号.例如,线程B可以等待线程A的一个信 ...
- Linux下iptables屏蔽IP和端口号
http://blog.csdn.net/kobejayandy/article/details/24332597 iptables 屏蔽端口
- RoundingMode 几个参数详解
第一版 java.math.RoundingMode 几个参数详解 java.math.RoundingMode里面有几个参数搞得我有点晕,现以个人理解对其一一进行总结: 为了能更好理解,我们可以画一 ...