对拍了一波才找到的错误,此题我用的是二分答案加倍增查询,实际上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. Html标签杂记

    <html> <head> <title> </title> </head> <body> </body> < ...

  2. iOS 中集成百度echarts3.0

    突然项目中要用到图表,所以就用了百度的echarts,然后就是网上搜了一下,由于本人的JS不是很熟悉,但是研究了一下还是做出来了,其实也不是很难 最后做的效果大概如下图这种,由于界面上没调整,所以粗糙 ...

  3. 实现上下全屏幕屏滚动效果js

    ---恢复内容开始--- 详情见代码 第一步:首先添加3个js文件: 1.http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js 2.http://c ...

  4. redis 可视化管理工具

    Redis Desktop Manager 下载地址:http://redisdesktop.com/download 支持: Windows 7+, Mac OS X 10.10+, Ubuntu ...

  5. java web 学习笔记 - tomcat数据源

    1. 数据库源 以前的JDBC连接步骤为: 1.加载数据库驱动 2.通过DriverManger获取数据库连接connection 3.通过connection执行prepareStatement的响 ...

  6. win7电脑桌面壁纸曝光过高影响图标怎么办?亲测实用解决方法

    现在用win7系统的人应该还是挺多的吧,虽然说windows家族已经升级到现在的win11了,相信大多数人家用的电脑系统还是win7吧,今天要讲的是一个壁纸曝光度过高的解决办法,虽然还不清楚为什么,但 ...

  7. Seating Arrangement

    1997: Seating Arrangement Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 543     Solved:  ...

  8. hibernate 批量抓取

    使用场景: 是查询出来一个集合,然后又查询每个集合对象中的集合.使用set标签中的batch-size属性实现. 数据库中只有5个区道信息: 设置batch-size=”5”,执行的查询语句如下: 而 ...

  9. chat - 和数据集沟通的指令稿

    总览 SYNOPSIS chat [ options ] script 描述 DESCRIPTION chat 程式在電腦與數據機之間定義溝通交換事宜. 它最主要的目的是用來在點對點協定的隱形程式 ( ...

  10. CS2QS

    inline QString MotorCS2QS(CString cs) { return QString::fromWCharArray((LPCTSTR)cs, cs.GetLength()); ...