首页 > 其他分享 >CF1971F Circle Perimeter

CF1971F Circle Perimeter

时间:2024-06-03 19:44:42浏览次数:13  
标签:Perimeter distance CF1971F lattice LL leq test integer Circle

题目

Given an integer \(r\), find the number of lattice points that have a Euclidean distance from \((0, 0)\) greater than or equal to \(r\) but strictly less than \(r+1\).

A lattice point is a point with integer coordinates. The Euclidean distance from \((0, 0)\) to the point \((x,y)\) is \(\sqrt{x^2 + y^2}\).
https://codeforces.com/contest/1971/problem/F

Input

The first line contains a single integer \(t\) (\(1 \leq t \leq 1000\)) — the number of test cases.The only line of each test case contains a single integer \(r\) (\(1 \leq r \leq 10^5\)).
The sum of \(r\) over all test cases does not exceed \(10^5\).

6
1
2
3
4
5
1984

Output

For each test case, output a single integer — the number of lattice points that have an Euclidean distance \(d\) from \((0, 0)\) such that \(r \leq d < r+1\).

8
16
20
24
40
12504

题解

解题思路

注意到数据范围为1e5级别,需要线性时间复杂度,故考虑枚举一个数并快速算出另外一个数
对公式\(r \leq \sqrt{x^2 + y^2} \leq r+1\)进行变形,可以得知需要枚举x(范围为\((-r,r)\)),利用公式求出y从而快速计算,注意边界情况:\(x^2+y^2 \leq (r+1)^2-1\)

Code

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long LL;
signed main(){
	IOS;
    int _;cin>>_;
    while(_--){
        LL n;cin>>n;
        LL ans=0;
        for(LL i= -n;i<=n;i++){
            LL t1=ceil(sqrtl(n*n-i*i));
            LL t2=sqrtl((n+1)*(n+1)-i*i-1);
            ans+=(t2-t1+1)*2-(t1==0);
        }
        cout<<ans<<endl;
    }
	
	return 0;
}

标签:Perimeter,distance,CF1971F,lattice,LL,leq,test,integer,Circle
From: https://www.cnblogs.com/TaopiTTT/p/18229494

相关文章

  • 【白鲸优化算法】 tent、chebyshev、Singer、Logistic、Sine, Circle多种混沌初始化的
     ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,代码获取、论文复现及科研仿真合作可私信。......
  • 【白鲸优化算法】 tent、chebyshev、Singer、Logistic、Sine, Circle多种混沌初始化的
     ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,代码获取、论文复现及科研仿真合作可私信。......
  • CIRCLEQ_INSERT_AFTER, C语言循环队列
     CMakeLists.txt#CMakeList.txt:CMakeprojectforllist,includesourceanddefine#projectspecificlogichere.#cmake_minimum_required(VERSION3.2)#Addsourcetothisproject'sexecutable.add_executable(poj2823"main.c""......
  • AWTK slider_circle 控件发布
    slider_circle控件。主要特色:支持正向和反向支持设置滑块的半径支持背景线宽和颜色支持前景线宽和颜色支持设置是否显示值的文本支持设置起始角度和结束角度支持设置格式化值的格式字符串支持使用图片填充背景和前景界面效果:注意:水平向右为0度,顺时针为正,逆时针为负......
  • 题解 CF963E Circles of Waiting
    令\(f_{i,j}\)表示\((i,j)\)走出以\((0,0)\)为圆心,半径为\(R\)的期望步数,显然所有在圆外的点\((i,j)\)满足\(f_{i,j}=0\)。有\(f_{i,j}=p_1f_{i-1,j}+p_2f_{i,j-1}+p_3f_{i+1,j}+p_4f_{i,j+1}\)。这东西很套路,高斯消元就行,但状态数是\(O(R^2)\)的,复杂度\(O(R^......
  • 「悬浮捷径SoftCircle」安卓平台的hao123,一键打开万物
    罗老师的onestep一步发布之前,终端的打开形式还拘泥于桌面和负一屏这种方式够简洁,但缺点明显:1.入口单一性:只能在app首页和各种扫一扫之间选择和切换2.操作复杂:入口切换需要频繁的进入退出桌面,步骤过于繁杂以下是悬浮捷径SoftCircle的解决方式1.入口的丰富性:安卓平台......
  • Cognex 的 CogFitCircle 和 CogNPointToNPoint 类的简单测试
    privatevoidbtn_Test_Click(objectsender,RoutedEventArgse){CogFitCirclecogFitCircle=newCogFitCircle();cogFitCircle.AddPoint(0,10);cogFitCircle.AddPoint(10,0);cogFitCircle.AddPoint(0,-10);cogFitCircle.AddPoint(-10,0);......
  • AGC020F Arcs on a Circle
    一个和值域无关的算法,复杂度\(O(4^nn^2)\),不过好像可以用子集卷积和拉格朗日插值优化至\(O(3^nn^3)\)。如果说原问题在整数上做,我们通常可以用生成函数来刻画容斥的式子,求个二维\(\exp\)状物就可以了,但是在实数域似乎不太好扩展,但实际上是可以扩展的。原问题实际上可以抽象......
  • halcon-轮廓拟合圆fit_circle_contour_xld
    fit_circle_contour_xld(xld,'algebraic',-1,0,0,3,2,Row,Column,Radius,StartPhi,EndPhi,PointOrder)*对XLD轮廓做近似圆计算--拟合圆--获得圆数据*参数1:输入xld轮廓*参数2:圆的拟合算法*'ahuber'对轮廓点进行加权,以减少异常值的影响*'......
  • 队列和循环队列(ArrayQueueAndCircleQueue)
    队列数组队列1.初始化队列privateintmaxsize;//最大长度privateintfront;//指向队首的前一个位置privateintrear;//指向队尾privateint[]arr;publicArrayQueue(intmaxsize){this.maxsize=maxsize;arr=newint[maxsize];......