1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atcoder解いてみた ABC 133 B - Good Distance

1
Posted at

#ABC 133 B - Good Distance 解答例
問題はこちら

#include <iostream>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int N; // 点の数2<=, <=10
    int D; // 次元数1<=, <=10
    int X[10][10]; // 一次元目:点の数, 二次元目:次元数

    cin >> N;
    cin >> D;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int intDist = 0;
    int count = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {

            float sum = 0;
            for (int k = 0; k < D; k++) {
                sum += powf(abs(X[i][k] - X[j][k]), 2);
            }
            float dist = sqrt(sum);
            intDist = static_cast<int>(dist);
            if (static_cast<float>(intDist) == dist) {
                count++;
            }
        }
    }

    std::cout << count << std::endl;

    return 0;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?