2016 ICPC 北京网络赛I题Countries,hiho1391 : Countries

链接:http://hihocoder.com/problemset/problem/1391

题意:有两个国家A,B,他们都有一个防御系统但是只给出B过的防御时间区间和A国的防御时间长度。然后A会发射若干导弹打向B国,B也会发射一下导弹,当一个导弹打到一个国家时如果碰到这在防御那么就会将导弹反弹会敌方。求何时开启A国的防御系统受到的伤害最小。

分析:A国想要防御住一个导弹一定是要覆盖这个导弹的时间直到这枚导弹是打到了B国,那么抽象出的模型就是确定一个长度为L的区间使得这个区间覆盖的导弹伤害最大(这样自己的伤害就最小啦)。这样的话就是一个区间覆盖最大价值的问题啦,一个常见的模型将导弹的区间按r排序然后将L的右端点枚举确定然后看能覆盖到的最大值就行了,离散化后用一个树状数组维护下就好了。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50010;
const int mod=1000000007;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1ll<<55;
const double eps=1e-5;
const double inf=~0u>>1;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct node {
    ll l,r,p;
}D[N];
ll x[N],f[N];
int cmd(node a,node b) {
    return a.r<b.r;
}
void add(int w,ll p) {
    for (;w<=N;w+=w&-w) f[w]+=p;
}
ll getsum(int w) {
    ll ret=0;
    for (;w;w-=w&-w) ret+=f[w];
    return ret;
}
int main()
{
    int i,g,k,K,num1,num2;
    ll a,b,p,n,m,sum,mx,L,R;
    while (scanf("%lld%lld", &n, &m)!=EOF) {
        scanf("%lld", &L);
        R=L+m;g=0;sum=0;
        scanf("%d%d", &num1, &num2);
        for (i=1;i<=num1;i++) {
            scanf("%lld%lld%lld", &a, &b, &p);
            if (a+b<L||a+b>R) continue ;
            else {
                g++;D[g].l=a+2*b;D[g].p=p;sum+=p;
                D[g].r=a+2*b+(R-a-b)/(2*b)*(2*b);
            }
        }
        for (i=1;i<=num2;i++) {
            scanf("%lld%lld%lld", &a, &b, &p);
            g++;D[g].l=a+b;D[g].p=p;sum+=p;
            if (R<a+2*b||a+2*b<L) D[g].r=D[g].l;
            else D[g].r=a+3*b+(R-a-2*b)/(2*b)*(2*b);
        }
        for (k=0,i=1;i<=g;i++) {
            x[++k]=D[i].l;x[++k]=D[i].r;x[++k]=D[i].r-n;
        }
        sort(D+1,D+g+1,cmd);
        sort(x+1,x+k+1);
        K=unique(x+1,x+k+1)-(x+1);
        memset(f,0,sizeof(f));mx=0;
        for (i=1;i<=g;i++) {
            int w,pre,now;
            w=lower_bound(x+1,x+K+1,D[i].l)-x;
            now=lower_bound(x+1,x+K+1,D[i].r)-x;
            pre=lower_bound(x+1,x+K+1,D[i].r-n)-x;
            add(w,D[i].p);
            mx=max(mx,getsum(now)-getsum(pre-1));
        }
        printf("%lld\n", sum-mx);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值