19 秦皇岛 icpc A.Angle Beats//极角排序,卡常,卡精度

题目

思路

考虑以询问的点为直角点,枚举另外一点,二分另外一个原来的点。
考虑以原来的点为直角点,枚举询问的点,二分另外一个原来的点。
需要极角排序(用atan2的死了)
用不需要double 的叉积,>0为顺时针,<0为逆时针,=0在同一条直线上。
还需要计算一个点绕另一个点90°后的坐标。
关键的排序!
卡常。。cf跑得慢,hdu跑得快。

/*   Author : Rshs
 *   Data : 2020-01-15-15.05
 */
#include<bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define LL long long
#define LDB long double
#define MP make_pair
#define PII pair<int,int>
#define SZ(a) (int)a.size()
const LDB pai = acos(-1.0L);
const LDB eps = 1e-10;
const LL mod = 1e9 + 7;
const int MXN = 1e6 + 5;
struct no {
    LL x, y;
};
no z[MXN];
LL cx, cy;
LL x[MXN], y[MXN];
LL ans[MXN];
inline int xiang(no &a) { // 分象限
    if(a.x >= 0 && a.y >= 0)  return 1;
    if(a.x < 0 && a.y >= 0)  return 2;
    if(a.x < 0 && a.y < 0)  return 3;
    if(a.x >= 0 && a.y < 0)  return 4;
    return 0;
}


LL corss(no &a, no &b) {
    return a.x * b.y - a.y * b.x;
}
bool operator<(const no &x, const no &y) { //自定义排序,先按象限排,再按叉积
    no a = {x.x - cx, x.y - cy};//转化成向量
    no b = {y.x - cx, y.y - cy};
    int qx = xiang(a), qy = xiang(b);
    if(qx != qy) return qx < qy;
    return corss(a, b) > 0;
}
int main() {
    int n, q, pos;
    while(cin >> n >> q){
        for(int i = 1; i <= n + q; i++) {
            int sa, sb;
            scanf("%d%d", &sa, &sb);
            x[i] = sa, y[i] = sb;
            ans[i]=0;
        }
        for(int i = n + 1; i <= n + q; i++) {
            cx = x[i], cy = y[i];
            pos = 0;
            for(int j = 1; j <= n; j++) {
                z[pos++] = no{x[j], y[j]};
            }
            sort(z, z + pos);
            for(int j = 1; j <= n; j++) {
                no aa = {x[i] + y[i] - y[j], y[i] - (x[i] - x[j])};//90oc
                ans[i] += (LL)(upper_bound(z, z + pos, aa) - lower_bound(z, z + pos, aa));
            }
        }
        for(int i = 1; i <= n; i++) {
            cx = x[i], cy = y[i];
            pos = 0;
            for(int j = 1; j <= n; j++) {
                if(i == j)continue;
                z[pos++] = no{x[j], y[j]};
            }
            sort(z, z + pos);
            for(int j = n + 1; j <= n + q; j++) {
                no aa = {x[i] + y[i] - y[j], y[i] - (x[i] - x[j])};//90oc
                no bb = {x[i] - (y[i] - y[j]), y[i] + (x[i] - x[j])};//另一方向
                ans[j] += (LL)(upper_bound(z, z + pos, aa) - lower_bound(z, z + pos, aa));
                ans[j] += (LL)(upper_bound(z, z + pos, bb) - lower_bound(z, z + pos, bb));
            }
        }
        for(int i = n + 1; i <= n + q; i++) cout << ans[i] << '\n';
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值