关于ABC D代码
  • 板块灌水区
  • 楼主cyx012113
  • 当前回复7
  • 已保存回复7
  • 发布时间2025/1/18 21:44
  • 上次更新2025/1/19 09:44:49
查看原帖
关于ABC D代码
1099138
cyx012113楼主2025/1/18 21:44

rt,不小心算出了近似圆周率。

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

long long count_squares_in_circle(int R) {
    long long count = 0;
    long long R2 = (long long)R * R;

    for (int i = -R; i <= R; ++i) {
        if ((i + 0.5) * (i + 0.5) > R2) {
            continue;
        }

        int max_j = floor(sqrt(R2 - (i + 0.5) * (i + 0.5)));
        int min_j = ceil(-sqrt(R2 - (i + 0.5) * (i + 0.5)));

        if (max_j >= min_j) {
            count += (max_j - min_j + 1);
        }
    }

    return count;
}

int main() {
    int R;
    cin >> R;

    cout << count_squares_in_circle(R) << endl;

    return 0;
}
2025/1/18 21:44
加载中...