首页 > 其他 > 详细

GYM 101572C(模拟)

时间:2019-05-24 15:32:13      阅读:56      评论:0      收藏:0      [点我收藏+]

要点

  • 题意是:以颜色red举例,逆时针找最近的,顺时针找最近的,相减得到val;对三种颜色都做这事然后求和,卖掉最小的,更新,继续。
  • 360度很小所以就像365天一样可以暴力前后扫。每次更新最多6个所以就是模拟题了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

const int maxn = 1e5 + 5;
int n;
struct Card {
    int c[3], id;
}a[maxn];
struct node {
    int val, id;
    bool operator < (const node &rhs) const {
        if (val != rhs.val) return val < rhs.val;
        return id > rhs.id;
    }
};
set<int> s[3][360];
set<node> S;
map<int, int> mp;
int V[maxn];

int getval(int i) {
    int sum = 0;
    for (int j = 0; j < 3; j++) {
        int cur = a[i].c[j];
        if (s[j][cur].size() >= 2)  continue;
        int l = cur;
        do {
            l = (l - 1 + 360) % 360;
        } while (s[j][l].size() == 0);
        int r = cur;
        do {
            r = (r + 1) % 360;
        } while (s[j][r].size() == 0);
        if (l > cur)    l -= 360;
        if (r < cur)    r += 360;
        sum += r - l;
    }
    return sum;
}

void deal(int j, int pos) {
    if (s[j][pos].size() >= 2)  return;
    int id = *s[j][pos].begin();
    int val = getval(mp[id]);
    S.erase({V[mp[id]], id});
    S.insert({V[mp[id]] = val, id});
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            scanf("%d", &a[i].c[j]);
        }
        scanf("%d", &a[i].id);
        int id = a[i].id;
        mp[id] = i;
        for (int j = 0; j < 3; j++) {
            s[j][a[i].c[j]].insert(id);
        }
    }
    for (int i = 0; i < n; i++) {
        V[i] = getval(i);
        S.insert({V[i], a[i].id});
    }
    while (n--) {
        int id = S.begin()->id;
        printf("%d\n", id);
        S.erase(S.begin());
        int t = mp[id];
        for (int j = 0; j < 3; j++) {
            int k = a[t].c[j];
            if (s[j][k].size() >= 2) {
                s[j][k].erase(s[j][k].find(id));
                int iid = *s[j][k].begin(), vval = getval(mp[iid]);
                S.erase({V[mp[iid]], iid});
                S.insert({V[mp[iid]] = vval, iid});
            } else if (n >= 1) {
                s[j][k].erase(s[j][k].begin());
                int l = k;
                do {
                    l = (l - 1 + 360) % 360;
                } while (s[j][l].size() == 0);
                deal(j, l);
                int r = k;
                do {
                    r = (r + 1) % 360;
                } while (s[j][r].size() == 0);
                deal(j, r);
            }
        }
    }
}

GYM 101572C(模拟)

原文:https://www.cnblogs.com/AlphaWA/p/10918058.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!