1005 继续(3n+1)猜想
#include"iostream" #include"vector" #include"algorithm" using namespace std; bool hashtable[20000] = {false}; //因为待映射的值可能比较大,所以数组开大一点,不然最后两个测试点会出现 段错误 bool cmp(const int& a,const int& b) { return a>b; } int n,a[200]; int main() { cin>>n; for(int i = 0; i < n; ++i) { scanf("%d",&a[i]); int t = a[i]; while(t != 1) { if(t%2 == 0) t/=2; else t = (3*t+1)/2; hashtable[t] = true; } } vector<int> vi; for(int i = 0; i < n; ++i) { if(hashtable[a[i]] == false) vi.push_back(a[i]); } sort(vi.begin(),vi.end(),cmp); for(int i = 0 ; i < vi.size(); ++i) { cout<<vi[i]; if(i < vi.size() - 1) cout<<" "; } return 0; }