#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#define N 20000
using namespace std;
int Max(int x,int y){if(x<y) return y;return x;}
int p[N];
struct seg
{
int s,e;
seg(int _s=0,int _e=0){s=_s,e=_e;}
}a[N];
int k[N],top,top2,m[N];
int M(int s,int e)
{
if(s==e) return p[e];
int mid=(s+e)>>1;
return Max(M(s,mid),M(mid+1,e));
}
int M2(int s,int e)
{
int ans;
top=0;top2=0;
a[++top]=seg(s,e);k[top]=0;
L:;
if(a[top].s==a[top].e) {ans=p[a[top].s];goto OUT;}
for(;k[top]<2;k[top]++)
{
if(k[top]==0) a[top+1]=seg(a[top].s,(a[top].s+a[top].e)/2);
else a[top+1]=seg((a[top].s+a[top].e)/2+1,a[top].e);
k[top+1]=0;
top++; goto L;
Z:;
}
a
带返还值的非递归 bs算法为例子
最新推荐文章于 2022-10-03 21:31:54 发布