2015
04-11

# 继续xxx定律

1<=n<=500
1<a[i]<=1000

1<=n<=500
1<a[i]<=1000

3
3 8 4
5
3 8 4 7 15
5
3 8 4 15 7
0

3
15 7 3
7 15 3

1、先把输入的数据全部当做关键数，并求其覆盖数，如果其覆盖数在数组内，标记。

2、最后倒序输出没有标记的数即可。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1100;
int main()
{
int n,a[N],f[N],i,j;
while(scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
memset(f,0,sizeof(f));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
f[a[i]]=1;          //初始化标记
}
for(i=0;i<n;i++)
{
if(f[a[i]]==0)    //如果已经存在不必再求，节省时间
continue;
else
j=a[i];
while(j>1)
{
if(j%2==1)
{
j=(j*3+1)/2;
}
else
j=j/2;
if(j<N)
{
f[j]=0;    //将覆盖数标记
}

}

}j=0;
for(i=n-1;i>=0;i--)
{
if(f[a[i]]&&j==1)
printf(" %d",a[i]);       //倒序输出没有被标记的数，注意格式、
if(f[a[i]]&&j==0)
{
printf("%d",a[i]);
j=1;
}

}
printf("\n");
}
return 0;
}

1. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.