Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. double get_prob(double x, double n) {
  2.     return exp(-x / n) / sqrt(pi * n);
  3. }
  4.  
  5. int main() {
  6.     int n; // 16
  7.     cin >> n;
  8.     vector<pair<double, double> > P(n);
  9.     for (int i = 0; i < n; i++) {
  10.         cin >> P[i].first >> P[i].second;
  11.     }
  12.  
  13.     const double MAX_CORD = 10;
  14.     const double STEP = 0.3;
  15.     const double N0 = 1; // sigma
  16.     double P_X = 1.0 / n;
  17.     double sum = 0;
  18.  
  19.     for (double x = -MAX_CORD; x <= MAX_CORD; x += STEP) {
  20.         for (double y = -MAX_CORD; y <= MAX_CORD; y += STEP) {
  21.             if (x * x + y * y > 0.01) {
  22.                 double p_y = 0;
  23.                 for (int i = 0; i < n; i++) {
  24.                     double dx = x - P[i].first;
  25.                     double dy = y - P[i].second;
  26.                     double p_y_xi = get_prob(dx * dx + dy * dy, N0);
  27.                     p_y += p_y_xi * P_X;
  28.                 }
  29.                 for (int i = 0; i < n; i++) {
  30.                     double dx = x - P[i].first;
  31.                     double dy = y - P[i].second;
  32.                     double p_y_x = get_prob(dx * dx + dy * dy, N0);
  33.                     double f = p_y_x * P_X * log(p_y_x / p_y);
  34.                     sum += f * STEP * STEP;
  35.                 }
  36.             }
  37.         }
  38.     }
  39.     printf("%0.10f", sum);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement