HDU4866-Shooting

本文介绍了一个射击游戏场景下的算法问题,玩家需要选择位置射击并获取最大化的积分奖励。文章详细阐述了通过主席树数据结构来解决该问题的过程,包括输入处理、主席树更新与查询等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shooting

                                                                     Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
                                                                                             Total Submission(s): 2534    Accepted Submission(s): 582


Problem Description
In the shooting game, the player can choose to stand in the position of [1, X] to shoot, you can shoot all the nearest K targets. The value of K may be different on different shootings. There are N targets to shoot, each target occupy the position of [Li, Ri] , the distance from the starting line is Di(1<=i<=N). Shooting a target can get the bonus points equal to the distance to the starting line. After each shooting targets still exist. Additional, if the previous bonus points is more than P, then as a reward for the shooting present bonus points doubled(and then check the next one). Player wants to know the bonus points he got in each shot.

 

Input
The input consists several test cases. 
The first line has two integers, N, M, X, P(1<=N, M ,X<=100000, P<=1000000000), N represents the total number of target shooting, M represents the number of shooting. 
The next N lines of three integers L, R, D (1<=L<=R<=X, 1<=D<=10000000), occupy the position of [L, R] and the distance from the starting line is D. 
The next M lines, each line contains four integers x, a, b, c (1<=x<=X, 0<=a,b<=N, 1<=c<=10000000), and K = ( a * Pre + b ) % c. Pre is the bonus point of previous shooting , and for the first shooting Pre=1. It denotes standing in the position x and the player can shoot the nearest K targets.
 

Output
Output M lines each corresponds to one integer.
 

Sample Input
  
4 3 5 8 1 2 6 2 3 3 2 4 7 1 5 2 2 2 1 5 3 1 1 10 4 2 3 7
 

Sample Output
  
11 10 18
 

Author
FZU
 

Source
 

题意:在一个射击游戏里面,游戏者可以选择地面上[1,X]的一个点射击,并且可以在这个点垂直向上射击最近的K个目标,每个目标有一个价值,价值等于它到地面的距离。游戏中有N个目标,每个目标从L到R,距离地面高度D。每次射击一个目标可以得到目标价值大小的分数,每次射击以后目标不会消失。如果在该点上方的目标个数小于可以射击的次数,那么就当多出来的次数全部射在该点上方最高的目标身上。并且如果你前一次游戏得到的分数如果大于P,那么这次你得到的分数就翻倍

解题思路:主席树,也可以对坐标进行离散化然后再建主席树


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;

int n,m,P,X,x,y,z,c,ma;
int res,s[100009],nt[200009],v[200009];
int ss[100009],L[30*200009],R[30*200009],cnt[30*200009],tot;
LL sum[30*200009];

void update(int pre,int &now,int l,int r,int val)
{
    now=++tot,L[now]=L[pre],R[now]=R[pre];
    cnt[now]=cnt[pre]+val/abs(val),sum[now]=sum[pre]+val;
    if(l==r) return ;
    int mid=(l+r)>>1;
    if(mid>=abs(val)) update(L[pre],L[now],l,mid,val);
    else update(R[pre],R[now],mid+1,r,val);
}

LL query(int k,int l,int r,int p)
{
    if(l==r) return 1LL*min(p,cnt[k])*l;
    int mid=(l+r)>>1;
    if(cnt[L[k]]<p) return sum[L[k]]+query(R[k],mid+1,r,p-cnt[L[k]]);
    return query(L[k],l,mid,p);
}

int main()
{
    while(~scanf("%d%d%d%d",&n,&m,&X,&P))
    {
        tot=ss[0]=L[0]=R[0]=res=ma=0;
        memset(s,-1,sizeof s);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            nt[res]=s[x],s[x]=res,v[res++]=z;
            nt[res]=s[y+1],s[y+1]=res,v[res++]=-z;
            ma=max(ma,z);
        }
        for(int i=1;i<=X;i++)
        {
            int k=ss[i-1];
            for(int j=s[i];~j;j=nt[j]) update(k,ss[i],1,ma,v[j]),k=ss[i];
            ss[i]=k;
        }
        LL pre=1;
        while(m--)
        {
            scanf("%d%d%d%d",&x,&y,&z,&c);
            pre=(pre>P?2:1)*query(ss[x],1,ma,1LL*(pre*y+z)%c);
            printf("%lld\n",pre);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值