// SwingSequence_2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
int main(int argc, char* argv[])
{
typedef struct _IntQuene
{
int arry[100];
int head;
int tail;
void Clear()
{
head=tail=0;
}
_IntQuene()
{
head=tail=0;
}
bool IsFull()
{
return tail==-1;
}
bool IsEmpty()
{
return head==tail;
}
int InQuene(int num)
{
if(IsFull())
return -1;
arry[tail]=num;
++tail;
tail%=100;
if(tail==head)
tail=-1;
return num;
}
int OutQuene()
{
if(IsEmpty())
return -1;
int tmp=head;
++head;
head %= 100;
if(tail==-1)
{
tail=tmp;
}
return arry[tmp];
}
}IntQuene,*PIntQuene;
int n;
printf("输入n:\n");
scanf("%d",&n);
getchar();
//
int i;
int a[3000];
int index=2;
a[1]=1;
//int maxindex=0;
int max=0;
IntQuene IndexQuene;
while(index <= n)
{
if( index%2==0 )
{
i=index/2;
a[index]=a[i]+1;
}
else
{
i=index/2;
a[index]=a[i]+a[i+1];
}
if(a[index]>max)
{
max=a[index];
IndexQuene.Clear();
IndexQuene.InQuene(index);
}
else if(a[index]==max)
{
IndexQuene.InQuene(index);
}
index++;
}
printf("a[%d]=%d\n",n,a[n]);
printf("max=%d,maxindex= ",max);
while(!(IndexQuene.IsEmpty()))
{
printf("%d ",IndexQuene.OutQuene());
}
printf("\n");
//printf("Hello World!\n");
return 0;
}
/*
输入n:
2011
a[2011]=225
max=321,maxindex= 1707 1877
Press any key to continue
*/