对拍了一波才找到的错误,此题我用的是二分答案加倍增查询,实际上query那里我觉得仍然有缺陷,因为每一次我的查找还是在循环找到一个k使得x+2^k <= y,而错的地方也正在此地,一开始没有判断x+2^k > y,反而直接将k=y的二进制下的最大的为1的位置,以后一定要注意边界条件。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 2005
#define ull unsigned long long
#define ll long long
#define hashmod 99999839
#define mod 9997
int a[maxn];
int dp[maxn][],p[];
int n,k;
//dp(i,j) 表示区间[i,i+2^j]中的最大值
//dp(i,j) = max(dp(i,j-1),dp(i+2^(j-1),j-1);
//dp(i,j) = max(dp(i,j-1),q(i+2^(j-1)+1,i+2^j));
//如果查询[x,y]中的最大值则q(x,y) = max(dp(x,k),q(x+2^k+1,y)),x+2^k <= y,k <= log(y-x)
int bitsearch(int x){
int l = ,r = ,mid,ans;
while(l <= r){
mid = (l+r)>>;
if(p[mid] > x) r = mid - ;
else l = mid + ,ans = mid;
}
return ans;
}
int query(int x,int y){
if(x > y) return ;
if(x == y) return a[x];
int k = bitsearch(y);
while(x + p[k] > y) k--;
return max(dp[x][k],query(x+p[k]+,y));
}
bool judge(int m){
int t = n / m,sum = ;
for(int i = ;i <= t * m;i += t){
sum += query(i,i+t-);
}
if(sum > k) return true;
return false;
}
void init(){
p[] = ;
for(int i = ;i <= ;++i) p[i] = p[i - ] << ;
}
int main(){
// freopen("a.in","r",stdin);
// freopen("b.out","w",stdout);
init();
while(~scanf("%d%d",&n,&k)){
if(n < && k < ) break;
memset(dp,,sizeof(dp));
int Max = ;
for(int i = ;i <= n;++i) scanf("%d",&a[i]),dp[i-][] = max(a[i-],a[i]),Max = max(Max,a[i]);
dp[n][] = a[n];
int li = bitsearch(n) + ;
for(int j = ;j <= li;++j){
for(int i = ;i <= n;++i){
if(i + p[j] > n){
if(i + p[j - ] <= n) dp[i][j] = max(dp[i][j-],dp[i+p[j-]][j-]);
else dp[i][j] = dp[i][j-];
continue;
}
dp[i][j] = max(dp[i][j-],dp[i+p[j-]][j-]);
}
}
int l = ,r = n,mid,ans = -;
while(l <= r){
mid = (l + r) >> ;
if(judge(mid)){
ans = mid;
r = mid - ;
}
else l = mid + ;
}
printf("%d\n",ans);
}
return ;
}

csu1364 Interview的更多相关文章

  1. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  2. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  3. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  4. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  5. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  6. Pramp - mock interview experience

    Pramp - mock interview experience   February 23, 2016 Read the article today from hackerRank blog on ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. [译]Node.js Interview Questions and Answers (2017 Edition)

    原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...

  9. WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】

    http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...

随机推荐

  1. AJPFX解析关于编码ansi、GB2312、unicode与utf-8的区别

    大家平时遇到乱码问题是否有自己的一套解决方案?这篇文章就是介绍一下常用的编码方式关于编码ansi.GB2312.unicode与utf-8的区别 先做一个小小的试验: 在一个文件夹里,把一个txt文本 ...

  2. AJPFX总结正则表达式的概述和简单使用

    正则表达式的概述和简单使用* A:正则表达式        * 是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用.        * 作用:比如注 ...

  3. [BZOJ1083][SCOI2005]繁忙的都市 最小生成树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1083 由kruskal算法原理可知,我们对一张无向图做普通的最小生成树,连上的最后一条边就 ...

  4. bootstrap基本布局

    中文API bootstrap.cn   HTML5文档 类型   移动设备优先 width 属性控制设备的宽度.设置为 device-width 确保它能正确呈现在不同设备上. initial-sc ...

  5. Android学习笔记(九) SeekBar和RatingBar

    一.SeekBar的主要属性 -max -progress -secondaryProgress 二.onSeekBarChangeListener -onProgressChanged(SeekBa ...

  6. openID 无效

    1.appid 和秘钥一定要是你目前正在测试公众号的数据,如果 appid 和 秘钥是测试账号的,而目标测试业务是在正式的公众号,及时能取到acces——token ,也会报无效的openid 遇到的 ...

  7. axis2与eclipse的整合:开始一个简单的axis2 的demo

    1.下载axis2,现在axis2最新版本是axis2-1.6.2,下载地址:http://axis.apache.org/axis2/java/core/download.cgi 2.下载好的zip ...

  8. Vue.js——打包之后资源路径产生问题

    https://blog.csdn.net/qq_30632003/article/details/79353035 https://www.cnblogs.com/diantao/p/7776523 ...

  9. AWT编程时,Button按钮上的中文编程□□□

    今天学到AWT编程时,照着书上的代码打,代码如下: import java.awt.*; public class PanelTest{    public static void main(Stri ...

  10. 洛谷 P1886 滑动窗口 (数据与其他网站不同。。)

    题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...