不是特别会做,看了题解,好像还挺简单了,写代码写了挺长时间。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<iostream> #include<cmath> #include<algorithm> #define ll long long #define pii pair<int,int> #define PINF 0x7fffffff #define NINF 0x80000000 using namespace std; int n; int score[10005]; int cnts[1000005]; int cnts2[10005]; int main() { ios::sync_with_stdio(false); cin >> n; cnts[1] = n; for (int i = 1; i <= n; i++)cin >> score[i]; int maxV = 0; for (int i = 1; i <= n; i++) { if (score[i] != 1)cnts[score[i]]++; maxV = max(maxV, score[i]); for (int j = 2; j <= sqrt((double)score[i]); j++) { if (score[i] % j == 0) { cnts[j]++; if (j*j != score[i])cnts[score[i] / j]++; } } } for (int i = 1; i <= maxV; i++) { if(cnts[i]!=0)cnts2[cnts[i]] = i; } for (int i = n; i > 0; i--)cnts2[i] = max(cnts2[i], cnts2[i + 1]); for (int i = 1; i <= n; i++)cout << cnts2[i] << endl; } |