带返还值的非递归 bs算法为例子

#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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值