Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double get_prob(double x, double n) {
- return exp(-x / n) / sqrt(pi * n);
- }
- int main() {
- int n; // 16
- cin >> n;
- vector<pair<double, double> > P(n);
- for (int i = 0; i < n; i++) {
- cin >> P[i].first >> P[i].second;
- }
- const double MAX_CORD = 10;
- const double STEP = 0.3;
- const double N0 = 1; // sigma
- double P_X = 1.0 / n;
- double sum = 0;
- for (double x = -MAX_CORD; x <= MAX_CORD; x += STEP) {
- for (double y = -MAX_CORD; y <= MAX_CORD; y += STEP) {
- if (x * x + y * y > 0.01) {
- double p_y = 0;
- for (int i = 0; i < n; i++) {
- double dx = x - P[i].first;
- double dy = y - P[i].second;
- double p_y_xi = get_prob(dx * dx + dy * dy, N0);
- p_y += p_y_xi * P_X;
- }
- for (int i = 0; i < n; i++) {
- double dx = x - P[i].first;
- double dy = y - P[i].second;
- double p_y_x = get_prob(dx * dx + dy * dy, N0);
- double f = p_y_x * P_X * log(p_y_x / p_y);
- sum += f * STEP * STEP;
- }
- }
- }
- }
- printf("%0.10f", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement