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-6;
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 = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)) { x = x * 10 + c - ‘0‘; 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+1)-eps>r*r) return 0;
    if(dis(x,y-1)-eps>r*r) return 0;
    if(dis(x+sqrt3/2,y+0.5)-eps>r*r) return 0;
    if(dis(x+sqrt3/2,y-0.5)-eps>r*r) return 0;
    if(dis(x-sqrt3/2,y+0.5)-eps>r*r) return 0;
    if(dis(x-sqrt3/2,y-0.5)-eps>r*r) return 0;
    return 1;
}

int main()
{
    while(~scanf("%lf",&r))
    {
        LL ans=0, L=1,R=(LL)2000000,pos;
        while(L<=R)
        {
            LL mid=(L+R)/2;
            if(check((mid-1)*sqrt3,0)) pos=mid, L=mid+1;
            else R=mid-1;
        }
        LL cnt=0; double x=0,y=-3;
        while(1)
        {
            if(!check(x,y)) break;
            LL L=1,R=(LL)2000000,pp;
            while(L<=R)
            {
                LL mid=(L+R)/2;
                if(check(x-(mid-1)*sqrt3/2,y-(mid-1)*1.5)) pp=mid, L=mid+1;
                else R=mid-1;
            }
            pp=1+(pp-1)*2, cnt=cnt+pp, y=y-3;
        }
        ans=6*(pos-1)+1+6*cnt;
        printf("%lld\n",ans);
    }
    return 0;
}

CodeForces 78D Archer's Shot

时间: 2024-08-28 12:52:39

CodeForces 78D Archer's Shot的相关文章

CodeForces 312B Archer

Archer Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 312B64-bit integer IO format: %I64d      Java class name: (Any) SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to

hdu 5318 The Goddess Of The Moon 矩阵高速幂

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5318 The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 438    Accepted Submission(s): 150 Problem Description Chang'e (嫦娥) is

hdu 5318 The Goddess Of The Moon

The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 650 Problem Description Chang’e (嫦娥) is a well-known character in Chinese ancient mytholog

HDOJ 5318 The Goddess Of The Moon 矩阵快速幂

The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 540    Accepted Submission(s): 215 Problem Description Chang'e (嫦娥) is a well-known character in Chinese ancient mytholog

HDU 5318 The Goddess Of The Moon(矩阵快速幂详解)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5318 题面: The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 800    Accepted Submission(s): 349 Problem Description Chang'e (嫦

HDU 5318(The Goddess Of The Moon-矩阵乘法)[Template:矩阵]

The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1086    Accepted Submission(s): 489 Problem Description Chang'e (嫦娥) is a well-known character in Chinese ancient mytholo

【CodeForces 312B】BUPT 2015 newbie practice #3A Archer

题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the tar

Codeforces 594A - Warrior and Archer

题目大意:给你在一条线上的n(偶数)个点,mike和alice 开始禁点,他们轮流开始,直到最后只剩下两个点, mike希望剩下的两个点距离尽可能小,alice希望剩下的两个点距离尽可能大,他们都采用最优策略,问你最后 剩下的两个点是什么. 这种脑洞题好难啊啊,难受. 思路:我们假定剩下了两个点是 x1 和 x2 ,那么最优考虑,mike拿掉的是<x1 和 >x2的点,alice拿掉的是 x1 和 x2 之间的点,所以我们枚举x1 和 x2,因为mike先选,我们取其中的最小值. #inclu

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it