#include<bits/stdc++.h>
typedef int IT;
typedef long long LL;
typedef __int128 int128;
typedef double DB;
typedef long double LDB;
#define pb push_back
#define fst first
#define sec second
#define psh push
#define mkp make_pair
#define PII pair<IT,IT>
#define PLI pair<LL,IT>
#define lowbit(x) ((x)&(-x))
using namespace std;
const int N=2e5+10;
int R;
LL ans;
DB dis(DB x,DB y,DB p,DB q){
return sqrt((x-y)*(x-y)+(p-q)*(p-q));
}
bool check(int x,int y){
DB s[4]={dis(0,0,x+0.5,y+0.5),dis(0,0,x+0.5,y-0.5),
dis(0,0,x-0.5,y+0.5),dis(0,0,x-0.5,y-0.5)};
for(int i=0;i<4;i++)
if(s[i]>R) return 0;
// if(dis(0,0,x+0.5,y+0.5)<=R) return 1;
return 1;
}
int main(){
scanf("%d",&R);
for(int x=0;x<=R;x++){
int l=0,r=R,res=0;
while(l<=r){
int mid=(l+r)>>1;
if(check(x,mid)) l=mid+1,res=mid;
else r=mid-1;
}
// cout<<res<<endl;
ans+=res;
}
ans=(ans<<2)+1;
printf("%lld\n",ans);
return 0;
}
这里二分的 (x,y) 都是正数,感觉思路是对的(?)但是瞪了 30min 没看出来有啥问题。