hihocoder 1064 时间结界 扫描线

题目链接:http://hihocoder.com/problemset/problem/1064

题目描述:二维平面有 n个点,(n<=2000)坐标范围是[-10,10],每个点有一个权值,问一个单位圆最多能覆盖的最大权值是多少

解题思路:枚举每一个点,以这个点作为单位圆上的一点(也就是边界上的点),然后这个单位圆相当于固定了一个点,然后逆时针或顺时针做扫描线。维护一个最大值。

其实在做扫描线之前,需要先处理出一个结构体来,一个是角度——用来排序,一个是权值——用来维护答案

不过真的涨姿势了,居然有atan2(y,x)这么神奇的函数,省的自己写了。。。

弱渣就是弱渣,即使想出算法,还是不能AC

//#pragma comment(linker,"/STACK:102400000,102400000")
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define ll long long
#define db double
#define PB push_back
#define lson k<<1
#define rson k<<1|1
using namespace std;

const int N = 2005;
const db PI = acos(-1.0);
const db eps = 1e-8;

int sgn(db t)
{
    return t<-eps?-1:t>eps;
}

struct Point
{
    db x,y;
    int w;
    Point (db _x=0,db _y=0):x(_x),y(_y){}
    void input()
    {
        scanf("%lf%lf%d",&x,&y,&w);
    }
    db len2()
    {
        return x*x+y*y;
    }
    db len()
    {
        return sqrt(len2());
    }
    Point operator - (const Point &t) const
    {
        return Point(x-t.x,y-t.y);
    }
    bool operator == (const Point &t) const
    {
        return sgn(x-t.x)==0&&sgn(y-t.y)==0;
    }
    db operator * (const Point &t) const
    {
        return x*t.y-t.x*y;
    }
}p[N];

struct node
{
    db thta;
    int w;
    bool operator < (const node &t) const
    {
        if(thta==t.thta) return w>t.w;
        return thta<t.thta;
    }
} jd[N*4];

int ln;
void add(db thta,int w)
{
    jd[ln].thta=thta,jd[ln++].w=w;
    jd[ln].thta=thta+PI*2,jd[ln++].w=w;
}

int main()
{
#ifdef PKWV
    freopen("in.in","r",stdin);
#endif // PKWV
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) p[i].input();
    Point px;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        px=Point(p[i].x+1.0,p[i].y);
        ln=0;
        int nw=p[i].w;
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
//                if(p[i]==p[j]) nw+=p[j].w;
//                else
//                {
                    db d=(p[i]-p[j]).len();
                    if(d>2.0) continue;
                    db thta=atan2((p[j]-p[i]).y,(p[j]-p[i]).x);
//                    if(sgn(d-2.0)==0)
//                    {
//                        add(thta,p[j].w),add(thta,-p[j].w);
//                    }else if(sgn(d-2.0)<0)
//                    {
                        db th=acos(d/2.0);
                        add(thta-th,p[j].w),add(thta+th,-p[j].w);
//                    }
//                }
            }
        }
        sort(jd,jd+ln);
        int mm=nw;
//        printf("***********\n");
//        for(int j=0;j<ln;j++) printf("%f %d\n",jd[j].thta,jd[j].w);
        for(int j=0;j<ln;j++) nw+=jd[j].w,mm=max(mm,nw);
//        printf("%d\n",mm);
        ans=max(ans,mm);
    }
    printf("%d\n",ans);
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值