标签:art n+1 图片 iostream div enc while for zha
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 bool cmp(int a, int b) { 6 return a > b; 7 } 8 int main() { 9 int K, flag = 0; 10 cin >> K; 11 int a[10000] = { 0 }; 12 vector<int> v; 13 for (int i = 0; i < K; i++) { 14 int tmp; 15 cin >> tmp; 16 v.push_back(tmp); 17 while (tmp != 1) { 18 if (tmp % 2 == 1) 19 tmp = 3 * tmp + 1; 20 tmp /= 2; 21 if (a[tmp] == 0) 22 a[tmp] = 1; 23 } 24 } 25 sort(v.begin(), v.end(), cmp); //重新排序 26 for (int i = 0; i < v.size(); i++) { 27 if (a[v[i]] == 0) { 28 if (flag == 1) cout << " "; 29 cout << v[i]; 30 flag = 1; 31 } 32 } 33 return 0; 34 }
来源:https://blog.csdn.net/zhanshen112/article/details/84310167
本题不太会(本人太菜了),感谢这位博主提供好方法,得以学习
对C++的库了解甚少,专门查了查官方文档:http://www.cplusplus.com/reference/algorithm/
里面sort函数的解释:
标签:art n+1 图片 iostream div enc while for zha
原文地址:https://www.cnblogs.com/SCP-514/p/13190959.html