CF 1971 F. Circle Perimeter (*1600) 思维 数学

CF 1971 F. Circle Perimeter (*1600) 思维 数学

题目链接

题意

找出平面直角坐标系中所有到原点距离 d , 满足 rd<r+1 的所有整数坐标点。

思路

注意到所有的都是对称出现的,因此我们只需要找出第一象限的点然后乘 4 即可。

我们可以枚举从 1r 横坐标,然后算出纵坐标的范围即可。对于当前枚举的横坐标 x

rx2+y2<r+1 。平方一下得: r2x2+y2<(r+1)2

移项得: r2x2y2<(r+1)2x2 。开根得: r2x2y<(r+1)2x2

所以有 ymin=r2x2 , ymax=(r+1)2x2eps

代码

#include<bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define all(u) u.begin(), u.end()
#define endl '\n'
#define debug(x) cout<<#x<<":"<<x<<endl;

typedef pair<int, int> PII;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10, M = 105;
const int mod = 1e9 + 7;
const int cases = 1;
const double eps = 0.5;

void Showball(){
   int r;
   cin>>r;
   LL ans=0;
   auto f=[&](LL n){return n*n;};
   for(LL i=1;i<=r;i++){
      LL maxn=floor(sqrt(f(r+1)-f(i)-eps));
      LL minn=ceil(sqrt(f(r)-f(i)));
      ans+=maxn-minn+1;
   }
   cout<<ans*4<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T=1;
    if(cases) cin>>T;
    while(T--)
    Showball();
    return 0;
}
posted @   Showball  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示