zoukankan      html  css  js  c++  java
  • hihocoder1391 Country

    题解的那种前缀和以前没学过,感觉是种套路

    #include<bits/stdc++.h>
    using namespace std;
    const int INF = 0x3f3f3f3f;
    const int MAXN = 1e4+5;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    int Ta,Tb,X;
    int N,M;
    struct Node{
        int st,ti,da; 
        void inpu() {
            scanf("%d %d %d",&st,&ti,&da);
        }
    }A[MAXN],B[MAXN*2];
    map<int,int> mp;
    map<int,int>::iterator it;
    
    
    int main(){
        while(~scanf("%d %d %d",&Ta,&Tb,&X)) {
            mp.clear();
            scanf("%d %d",&N,&M);
            int tot = 0; int ans; 
            for(int i = 1; i <= N; ++i) A[i].inpu();
            for(int i = 1; i <= M; ++i) B[i].inpu(); 
    
    
            int st = X; int ed = X+Tb;
            for(int i = 1; i <= N; ++i) {
                if(A[i].st+A[i].ti >= st && A[i].st+A[i].ti <= ed) {
                    B[++M].st = A[i].st+A[i].ti; B[M].ti = A[i].ti; B[M].da = A[i].da;
                }   
            }
    
            for(int i = 1; i <= M; ++i) {
                tot += B[i].da; int k = 0;
                if(B[i].st+2*B[i].ti >= st && B[i].st+2*B[i].ti <= ed) {
                    k = (ed-B[i].st-2*B[i].ti)/2/B[i].ti + 1;
                }
    
                int t1 = B[i].st+B[i].ti; int t2 = t1+2*k*B[i].ti;
                if(t2-Ta < t1+1) {
                    mp[t2-Ta] -= B[i].da; mp[t1+1] += B[i].da;
                }
            }
    
            ans = tot;
            for(it = mp.begin(); it != mp.end(); ++it) {
                tot += it->second;
                ans = min(ans,tot);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    
  • 相关阅读:
    反馈更多的信息,让别人感到舒服。
    Centos 安装Redis
    CentOS用yum安装MySQL 8.0 .
    MySQL事务。
    Java垃圾回收。
    类加载机制与类加载器。
    Java内存模型。
    844--Backspace String Compare
    maven的配置及基本操作
    idea基本使用
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433746.html
Copyright © 2011-2022 走看看