簡單題,但爲啥我算錯了,各種格式錯+運行超時,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;
}