简单题,但为啥我算错了,各种格式错+运行超时,debug没de出来,最后对着答案检查才发现都是小错误,比如把t写成了n,t%2 写成了t/2…
我发现,对于我这种脑残选手,写代码的时候千万不要仗着脑子暂时还好使就不动笔,就算再思路明细的题,也一定要把框架搭起来,不然绕着绕着就晕了TAT
思路待补------------
/*输入样例:
6
3 5 6 7 8 11
输出样例:
7 6*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 10000;
bool hashTable[MAXN]={false};
int num[MAXN] = {0};
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&num[i]);
int t=num[i];
if(hashTable[t])
continue;
while(t!=1)
{
if(t%2==0)
t/=2;
else
t=(3*t+1)/2;
hashTable[t]=true;
}
}
int count=0;
for(int i=0;i<n;i++)
{
if(hashTable[num[i]]==false)
count++;
}
sort(num,num+n,cmp);
for(int i=0;i<n;i++)
{
int t=num[i];
if(!hashTable[t])
{
printf("%d",t);
count--;
if(count>0)
printf(" ");
}
}
return 0;
}