AtCoder Beginner Contest 133 B

地址:https://atcoder.jp/contests/abc133/tasks/abc133_b

核心问题:判断一个浮点数开方是否为整数

       double EPS=1e-10;
        double ans1=sqrt(ans);
        if(ans1-floor(ans1)<EPS)//是整数
           {
                  //
            }    

题解:

#include <iostream>
#include<cmath>
using namespace std;

//const double EPS 1e-10;
int a[20][20];
int main()
{
    int n,d;
    double EPS=1e-10;
    cin >> n >> d;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<d;j++)
        {
            cin >> a[i][j];
        }
    }

    int sum=0;
    for(int k=0;k<n;k++)
    {

    for(int i=k+1;i<n;i++)
    {
        double ans=0;
        for(int j=0;j<d;j++)
        {
            ans+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);
        }
        double ans1=sqrt(ans);
        if(ans1-floor(ans1)<EPS)
           sum++;
    }
    }
    cout << sum << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/wjc2021/p/11153682.html