题解:AT_abc389_d [ABC389D] Squares in Circle
数学题。
题意
给你一个铺满单位长度为
思路
假设有这样一个图:
如果以
可以发现,中间有个十字的部分是一定会被包含的。
记答案为
然后发现剩下可以分成完全相同的四部分,我们已左下角的来举例:
第一层 for 循环,表示横着是第
第二层 for 循环,表示竖着是第
想这样,发现复杂度是
发现随着
所以可以记录一个
每次判断
时间复杂度
Code
#include<bits/stdc++.h>
#define int long long
#define bug cout<<"___songge888___"<<'\n';
using namespace std;
int r;
int ans=1;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>r;
ans+=4*(r-1);
int pos=r-1;
int ans1=0;
for(int i=1;i<r;i++){
while((pos*1.0+0.5)*(pos*1.0+0.5)+(i*1.0+0.5)*(i*1.0+0.5)>r*r&&pos>0){
pos--;
}
ans1+=pos;
}
ans+=4*ans1;
cout<<ans;
return 0;
}