【Kickstart】2018 Round D - Paragliding

解法

对于每个气球(x,y),如果它可以被拿到,那么需要有塔,其塔尖(p,h)在阴影部分:
1

分析可知需要满足:
h ≥ ∣ p − x ∣ + y h\ge |p-x|+y hpx+y
,即 x + y ≥ p + h x+y\ge p+h x+yp+h y − x ≥ h − p y-x\ge h-p yxhp

把每个点从(x,y)进行坐标变换成(x+y,y-x)
所以对于每个气球,只要找有没有横纵坐标都比它大的塔即可。

#include <stdio.h>
#include <string>
#include <iostream>
#include <memory.h>
#include <stdlib.h>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>

#define MAXN 100010
#define NINF 0x80000000


using namespace std;

typedef long long lld;

struct POINT {
    int x,y;
    POINT(int a,int b):x(a),y(b) {}
    bool operator < (const POINT &b) const {
        if (x==b.x) return y<b.y;
        return x<b.x;
    }
};

vector<POINT> tower,ball;

int solve() {
    int ans = 0;
    int j = tower.size()-1;
    int maxval = NINF;
    for(int i = ball.size()-1;i>=0;i--) {
        POINT &p = ball[i];
        for(;j>=0 && tower[j].x>=p.x;j--) {
            maxval = max(maxval,tower[j].y);
        }
        if(maxval>=p.y) ans++;
    }
    return ans;
}

int main() {
    int t;
    scanf("%d",&t);
    for(auto round=1;round<=t;++round) {
        tower.clear();
        ball.clear();
        int n,k;
        scanf("%d%d",&n,&k);
        int x1,x2,y1,y2;
        lld a1,b1,c1,m1,a2,b2,c2,m2;
        scanf("%d%d%lld%lld%lld%lld",&x1,&x2,&a1,&b1,&c1,&m1);
        scanf("%d%d%lld%lld%lld%lld",&y1,&y2,&a2,&b2,&c2,&m2);
        tower.emplace_back(POINT(x1+y1,y1-x1));
        tower.emplace_back(POINT(x2+y2,y2-x2));
        for(int i=3;i<=n;++i) {
            int tmp1 = x2, tmp2 = y2;
            x2 = (a1*x2+b1*x1+c1)%m1+1;
            y2 = (a2*y2+b2*y1+c2)%m2+1;
            tower.emplace_back(POINT(x2+y2,y2-x2));
            x1 = tmp1;
            y1 = tmp2;
        }
        scanf("%d%d%lld%lld%lld%lld",&x1,&x2,&a1,&b1,&c1,&m1);
        scanf("%d%d%lld%lld%lld%lld",&y1,&y2,&a2,&b2,&c2,&m2);
        ball.emplace_back(POINT(x1+y1,y1-x1));
        ball.emplace_back(POINT(x2+y2,y2-x2));
        for(int i=3;i<=k;++i) {
            int tmp1 = x2, tmp2 = y2;
            x2 = (a1*x2+b1*x1+c1)%m1+1;
            y2 = (a2*y2+b2*y1+c2)%m2+1;
            ball.emplace_back(POINT(x2+y2,y2-x2));
            x1 = tmp1;
            y1 = tmp2;
        }
        sort(tower.begin(),tower.end());
        sort(ball.begin(),ball.end());
        printf("Case #%d: %d\n",round,solve());
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值