Description
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following nnumbers are the elements of the array (1 ≤ ai ≤ 100).
Output
Output space-separated elements of the sorted array.
Example
input
3 3 1 2
output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
排序。不过必须运行时间超过1s,不会怎么控制时间?有个好办法,随便找个代码,反正要运行1s以上的,加进去,然后输出结果就好了,这里我用了网络赛的代码
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 #define MAXN 100 5 #define MAXM 10001 6 #define MAXP 266666 7 #define MAX 3200001 8 #define clr(ar) memset(ar, 0, sizeof(ar)) 9 #define read() freopen("lol.txt", "r", stdin) 10 #define dbg(x) cout << #x << " = " << x << endl 11 #define chkbit(ar, i) (((ar[(i) >> 6]) & (1 << (((i) >> 1) & 31)))) 12 #define setbit(ar, i) (((ar[(i) >> 6]) |= (1 << (((i) >> 1) & 31)))) 13 #define isprime(x) (( (x) && ((x)&1) && (!chkbit(ar, (x)))) || ((x) == 2)) 14 15 16 namespace pcf 17 { 18 long long dp[MAXN][MAXM]; 19 unsigned int ar[(MAX >> 6) + 5] = {0}; 20 int len = 0, primes[MAXP], counter[MAX]; 21 22 void Sieve() 23 { 24 setbit(ar, 0), setbit(ar, 1); 25 for (int i = 3; (i * i) < MAX; i++, i++) 26 { 27 if (!chkbit(ar, i)) 28 { 29 int k = i << 1; 30 for (int j = (i * i); j < MAX; j += k) setbit(ar, j); 31 } 32 } 33 34 for (int i = 1; i < MAX; i++) 35 { 36 counter[i] = counter[i - 1]; 37 if (isprime(i)) primes[len++] = i, counter[i]++; 38 } 39 } 40 41 void init() 42 { 43 Sieve(); 44 for (int n = 0; n < MAXN; n++) 45 { 46 for (int m = 0; m < MAXM; m++) 47 { 48 if (!n) dp[n][m] = m; 49 else dp[n][m] = dp[n - 1][m] - dp[n - 1][m / primes[n - 1]]; 50 } 51 } 52 } 53 54 long long phi(long long m, int n) 55 { 56 if (n == 0) return m; 57 if (primes[n - 1] >= m) return 1; 58 if (m < MAXM && n < MAXN) return dp[n][m]; 59 return phi(m, n - 1) - phi(m / primes[n - 1], n - 1); 60 } 61 62 long long Lehmer(long long m) 63 { 64 if (m < MAX) return counter[m]; 65 66 long long w, res = 0; 67 int i, a, s, c, x, y; 68 s = sqrt(0.9 + m), y = c = cbrt(0.9 + m); 69 a = counter[y], res = phi(m, a) + a - 1; 70 for (i = a; primes[i] <= s; i++) res = res - Lehmer(m / primes[i]) + Lehmer(primes[i]) - 1; 71 return res; 72 } 73 } 74 75 long long solve(long long n) 76 { 77 int i, j, k, l; 78 long long x, y, res = 0; 79 80 /*for (i = 0; i < pcf::len; i++){ 81 printf("%I64d ",pcf::Lehmer(n)); 82 x = pcf::primes[i], y = n / x; 83 if ((x * x) > n) break; 84 res += (pcf::Lehmer(y) - pcf::Lehmer(x)); 85 } 86 87 for (i = 0; i < pcf::len; i++){ 88 x = pcf::primes[i]; 89 if ((x * x * x) > n) break; 90 res++; 91 }*/ 92 res=pcf::Lehmer(n); 93 return res; 94 } 95 int xx[100]; 96 int main() 97 { 98 pcf::init(); 99 long long n, res; 100 while(cin>>n) 101 { 102 int x=solve(100000000000); 103 for(int i=1; i<=n; i++) 104 { 105 cin>>xx[i]; 106 } 107 sort(xx+1,xx+n+1); 108 for(int i=1; i<=n; i++) 109 { 110 cout<<xx[i]<<" "; 111 } 112 } 113 return 0; 114 }