题解:AT_abc389_d [ABC389D] Squares in Circle

假定原点为圆心。

我们只考虑点在第一象限的情况,剩下的情况同理。

因为圆心是原点,所以在圆内的点的横坐标一定在 r 之内。

枚举点的横坐标 x+12,二分最大的 y+12,使得点 (x+12,y+12) 到原点的距离 r (因为我们令圆心为原点,所以所有的点都应平移一段)。

此时所有横坐标为 x+12 的在圆内的点分别是:

(x+12,12),(x+12,1+12),(x+12,2+12),,(x+12,y+12)

一共是 y+1 个。

将枚举的所有 x 算出来的答案加起来记为 t

因为我们只考虑了第一象限,所以答案是 4×t+1(需要考虑原点的情况,所以要 +1)。

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define FRE(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define ALL(x) x.begin(), x.end()
using namespace std;

inline void cmax(int& x, int c) {
    x = max(x, c);
}
inline void cmin(int& x, int c) {
    x = min(x, c);
}

int _test_ = 1;

int n, ans; 

double dis(double x, double y) {
    return (double)sqrt((double)((double)((double)x + 0.5) * (double)((double)x + 0.5) + (double)((double)y + 0.5) * (double)((double)y + 0.5)));
}

void init() {}

void clear() {}

void solve() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int l = 0, r = n, t = 0;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (dis(i, mid) <= (double)n) {
                t = mid;
                l = mid + 1;
            } else
                r = mid - 1;
        }
        ans += t + 1;
    }
    cout << ans * 4 + 1;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // cin >> _test_;
    init();
    while (_test_--) {
        clear();
        solve();
    }
    return 0;
}
posted @   Archippus  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示