HDU 2648 (map 水~)

题目链接:点击打开链接

题意:每一个东西每天加一点钱,询问每天价格变化后memory的排名.

用map随便搞,维护一下原来的价格和加完的价格.

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
#define maxn 11111

map <string, long long> mp;
int n, m;
const string aa = "memory";
struct node {
    string a;
    long long add;
}p[maxn];

int main () {
    //freopen ("in.txt", "r", stdin);
    while (scanf ("%d", &n) == 1) {
        mp.clear ();
        for (int i = 0; i < n; i++) {
            string a;
            cin >> a;
            mp[a] = 0;
        }
        scanf ("%d", &m);
        long long pre = 0, now = 0;
        int Rank = 1;
        long long cur = 0;
        for (int i = 0; i < m; i++) {
            for (int i = 0; i < n; i++) {
                cin >> p[i].add >> p[i].a;
                if (p[i].a == aa)
                    now += p[i].add;
            }
            for (int i = 0; i < n; i++) {
                if (mp[p[i].a] <= pre && mp[p[i].a]+p[i].add > now) {
                    Rank++;
                }
                else if (mp[p[i].a] > pre && mp[p[i].a]+p[i].add <= now) {
                    Rank--;
                }
                mp[p[i].a] += p[i].add;
            }
            pre = now;
            printf ("%d\n", Rank);
        }
    }
    return 0;
}


你可能感兴趣的:(HDU 2648 (map 水~))