• hdu4020水题


    挺水的,我是用n个set分别存下n个用户的广告,然后对于遍历一次所有用户的广告处理出ans数组,输出即可。

    /*
     * hdu4020/win.cpp
     * Created on: 2012-11-10
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 100100;
    const int MAXM = 500100;
    typedef long long LL;
    typedef set<pair<int, int> > MySet;
    int N, M, Q;
    MySet customer[MAXN];
    LL ans[MAXM];
    int get_int() {
        int res = 0, ch;
        while (!((ch = getchar()) >= '0' && ch <= '9')) {
            if (ch == EOF)
                return 1 << 30;
        }
        res = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9')
            res = res * 10 + (ch - '0');
        return res;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T, a, b, c;
        T = get_int();
        for(int t = 1; t <= T; t++) {
            N = get_int();
            M = get_int();
            Q = get_int();
            for(int i = 0; i < M; i++) {
                a = get_int();
                b = get_int();
                c = get_int();
                customer[a - 1].insert(make_pair(b, c));
            }
            memset(ans, 0, sizeof(ans));
            for(int i = 0; i < N; i++) {
                int len = customer[i].size();
                MySet::iterator it = customer[i].end();
                for(int j = 1; j <= len; j++) {
                    it--;
                    ans[j] += (*it).second;
                }
                customer[i].clear();
            }
            for(int i = 1; i <= M; i++) {
                ans[i] += ans[i - 1];
            }
            printf("Case #%d:\n", t);
            for(int i = 0; i < Q; i++) {
                a = get_int();
                if(a >= M) {
                    a = M;
                }
                printf("%I64d\n", ans[a]);
            }
        }
        return 0;
    }
  • 相关阅读:
    快学scala习题解答--第五章 类
    从头认识java-18.2 主要的线程机制(2)-Executors的使用
    关于Bootstrap的理解
    Raw-OS源代码分析之idle任务
    Scilab 的画图函数(3)
    HDU2586.How far away ?——近期公共祖先(离线Tarjan)
    Codeforces Round #311 (Div. 2) A,B,C,D,E
    presto访问 Azure blob storage
    Presto集群安装配置
    Presto架构及原理
  • 原文地址:https://www.cnblogs.com/moonbay/p/2766552.html
Copyright © 2020-2023  润新知