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;

}

你可能感兴趣的:(HDU)