CodeForces 78D Archer's Shot

时间:2021-12-30 06:27:00

二分。

统计过程如下图:

先统计红线上的个数,然后统计绿线上的个数,然后统计咖啡色线上的个数......一个一个往下统计就可以了。

CodeForces 78D Archer's Shot

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} double r;
double sqrt3=sqrt(3.0); double dis(double x,double y) { return x*x+y*y; } bool check(double x,double y)
{
if(dis(x,y+)-eps>r*r) return ;
if(dis(x,y-)-eps>r*r) return ;
if(dis(x+sqrt3/,y+0.5)-eps>r*r) return ;
if(dis(x+sqrt3/,y-0.5)-eps>r*r) return ;
if(dis(x-sqrt3/,y+0.5)-eps>r*r) return ;
if(dis(x-sqrt3/,y-0.5)-eps>r*r) return ;
return ;
} int main()
{
while(~scanf("%lf",&r))
{
LL ans=, L=,R=(LL),pos;
while(L<=R)
{
LL mid=(L+R)/;
if(check((mid-)*sqrt3,)) pos=mid, L=mid+;
else R=mid-;
}
LL cnt=; double x=,y=-;
while()
{
if(!check(x,y)) break;
LL L=,R=(LL),pp;
while(L<=R)
{
LL mid=(L+R)/;
if(check(x-(mid-)*sqrt3/,y-(mid-)*1.5)) pp=mid, L=mid+;
else R=mid-;
}
pp=+(pp-)*, cnt=cnt+pp, y=y-;
}
ans=*(pos-)++*cnt;
printf("%lld\n",ans);
}
return ;
}