abdukodir

D.cpp

Feb 13th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <assert.h>
  5. #include <vector>
  6. #include <string>
  7. #include <map>
  8. #include <set>
  9. #include <queue>
  10. #include <stack>
  11. #include <cstring>
  12. #include <algorithm>
  13. #define sc scanf
  14. #define pr printf
  15. #define pb push_back
  16. #define mp std::make_pair
  17. #define fr first
  18. #define se second
  19.  
  20. using namespace std;
  21.  
  22. typedef std::pair<int, int> pii;
  23. typedef std::pair<double, double> pdd;
  24.  
  25. const int MN = 10010;
  26. const long long M = -(1LL << 50);
  27. const long long MAX_LONG = std::numeric_limits<long long>::max();
  28. const long long MIN_LONG = std::numeric_limits<long long>::min() + (1LL << 54);
  29. const int MAX_INT = std::numeric_limits<int>::max();
  30. const int MIN_INT = std::numeric_limits<int>::min();
  31.  
  32. int n;
  33. int a[MN];
  34. int b[MN] = {0};
  35. long long sum[MN] = {0};
  36.  
  37.  
  38. int main() {
  39. //freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
  40. //freopen("path.in", "r", stdin); freopen("path.out", "w", stdout);
  41. sc("%d", &n);
  42. for (int i = 0; i < n; i++) {
  43. sc("%d", &a[i]);
  44. }
  45.  
  46. sort(a, a + n);
  47.  
  48. for(int i = 0; i < n; i++) {
  49. for (int j = i + 1; j < n; j++) {
  50. b[ (a[j] - a[i]) ]++;
  51. }
  52. }
  53.  
  54. sum[0] = b[0];
  55.  
  56. for (int i = 1; i < MN; i++) {
  57. sum[i] = sum[i - 1] + b[i];
  58. }
  59.  
  60. long double ans = 0.0;
  61.  
  62. for (int i = 0; i < MN; i++) {
  63. if (b[i] == 0) {
  64. continue;
  65. }
  66. for (int j = 0; j < i; j++) {
  67.  
  68. ans += (1.0L * (sum[i - j - 1] * b[i] * b[j]));
  69. //pr("%d %d: %Lf %Lf\n", i, j, (1.0 * b[i] * b[j] * sum[i - j - 1]), ans);
  70.  
  71. }
  72. }
  73.  
  74. pr("%.10Lf\n", (ans / sum[MN - 1]) / sum[MN - 1] / sum[MN - 1]);
  75.  
  76. return 0;
  77. }
Add Comment
Please, Sign In to add comment