hdu 5071 Chat(模拟)

题目链接:hdu 5071 Chat

题目大意:模拟题。。。注意最后说bye的时候只要和讲过话的妹子说再见。

解题思路:用一个map记录每个等级的妹子讲过多少话以及是否有这个等级的妹子。数组A和N记录等级的顺序,增加

删除等操作完全可以同过数组上的模拟,时间足够。T和flag标记是否有置顶窗口。

#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 5005;
typedef long long ll;

map<int, ll> C;
int x, N, A[maxn], T, flag;
vector<int> vec;

int find(int a) {
    for (int i = 0; i < N; i++)
        if (A[i] == a)
            return i;
    return N;
}

void add ()  {
    scanf("%d", &x);
    if (C.count(x))
        printf("same priority");
    else {
        A[N++] = x;
        C[x] = 0;
        printf("success");
    }
}

void close() {
    scanf("%d", &x);
    if (C.count(x)) {
        printf("close %d with %I64d", x, C[x]);
        C.erase(x);

        if (flag && T == x)
            flag = 0;

        int pos = find(x);
        for (int i = pos; i < N; i++)
            A[i] = A[i+1];
        N--;
    } else
        printf("invalid priority");
}

void chat() {
    scanf("%d", &x);
    if (N == 0)
        printf("empty");
    else {
        if (flag) {
            C[T] += x;
            vec.push_back(T);
        } else {
            C[A[0]] += x;
            vec.push_back(A[0]);
        }
        printf("success");
    }
}

void rotate() {
    scanf("%d", &x);
    if (x > N || x < 1)
        printf("out of range");
    else {
        int tmp = A[x-1];
        for (int i = x-1; i; i--)
            A[i] = A[i-1];
        A[0] = tmp;
        printf("success");
    }
}

void prior() {
    if (N == 0)
        printf("empty");
    else {
        int x = A[0], pos = 0;
        for (int i = 1; i < N; i++) {
            if (A[i] > x) {
                x = A[i];
                pos = i;
            }
        }

        int tmp = A[pos];
        for (int i = pos; i; i--)
            A[i] = A[i-1];
        A[0] = tmp;
        printf("success");
    }
}

void choose() {
    scanf("%d", &x);
    if (C.count(x)) {
        int pos = find(x);

        int tmp = A[pos];
        for (int i = pos; i; i--)
            A[i] = A[i-1];
        A[0] = tmp;
        printf("success");
    } else
        printf("invalid priority");
}

void top() {
    scanf("%d", &x);
    if (C.count(x)) {
        T = x;
        flag = 1;
        printf("success");
    } else
        printf("invalid priority");
}

void untop() {
    if (flag) {
        flag = 0;
        printf("success");
    } else
        printf("no such person");
}

void solve() {
    if (N == 0)
        return;

    if (flag && C[T])
        printf("Bye %d: %I64d\n", T, C[T]);

    for (int i = 0; i < N; i++) {
        if (flag && A[i] == T)
            continue;
        if (C[A[i]])
            printf("Bye %d: %I64d\n", A[i], C[A[i]]);
    }

    /*
       int t = flag ? T : A[0];
       if (C[t])
       printf("Bye %d: %I64d\n", t, C[t]);

       for (int i = vec.size() - 1; i >= 0; i--) {
       if (C.count(vec[i]) && t != vec[i]) {
       printf("Bye %d: %I64d\n", vec[i], C[vec[i]]);
       break;
       }
       }
       */
}

int main () {
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        N = T = flag = 0;
        vec.clear();
        C.clear();

        int Q;
        char op[10];
        scanf("%d", &Q);
        for (int i = 1; i <= Q; i++) {
            scanf("%s", op);
            printf("Operation #%d: ", i);
            if (strcmp(op, "Add") == 0)
                add();
            else if (strcmp(op, "Close") == 0)
                close();
            else if (strcmp(op, "Chat") == 0)
                chat();
            else if (strcmp(op, "Rotate") == 0)
                rotate();
            else if (strcmp(op, "Prior") == 0)
                prior();
            else if (strcmp(op, "Choose") == 0)
                choose();
            else if (strcmp(op, "Top") == 0)
                top();
            else if (strcmp(op, "Untop") == 0)
                untop();
            printf(".\n");
        }
        solve();
    }
    return 0;
}
时间: 2024-11-03 21:02:16

hdu 5071 Chat(模拟)的相关文章

hdu 5071 Chat(模拟|Splay)

Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 571    Accepted Submission(s): 136 Problem Description As everyone knows, DRD has no girlfriends. But as everyone also knows, DRD's friend

HDU 5071 Chat(2014鞍山B,模拟)

http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 702    Accepted Submission(s): 163 Problem Description As everyone knows, DRD has no girlfr

HDU 5071 Chat (神一般的模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 题面: Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 2195    Accepted Submission(s): 465 Problem Description As everyone knows, DRD has

HDU - 5071 Chat(模拟)

原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #define ll long long #define ull unsign

HDU 5071 Chat (14鞍山区域赛 B) 模拟

题意:无力写了. 解题思路:纯模拟 解题代码: 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月22日 星期三 15时51分59秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack>

HDU 5071 Chat(2014鞍山赛区现场赛B题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口标记为一种特殊的状态,在这种特殊的状态下优先级是最高的,聊天都是跟这个聊,而这个窗口并没有在实际上被提到最前面.还有就是每句后面都有句号.我本来可以1A的,但就是因为没看这个,所以一直WA也找不到原因. 暴力模拟就可以了,因为点最多只有5000个,不会超时,维护一个队列就可以了,但我为了方便判断是不

HDU 5071 Chat

题意: CLJ找了很多妹子-  (题目好没节操-)  对于CLJ和妹子的聊天对话框  有一下几种操作: add  加一个妹子在聊天窗队列末尾  假设这个妹子已经在队列中则add失败 close  关掉某个妹子的聊天窗体  假设没有这个妹子的对话框则close失败  假设成功要输出和这个妹子说过几个词 chat  和最前面妹子说一些话  假设没有窗体打开则chat失败 rotate  将某个妹子移到最前面  假设寻找妹子时发现超出队列范围则rotate失败 prior  将优先级最高妹子移到最前面

HDOJ 5071 Chat 模拟

大模拟: 1>saygoodbye要先对 always on top 的人说 2>对没有说过话的不要说good bye 3>用long long Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 337    Accepted Submission(s): 82 Problem Description As ever

hdu 5071 Chat-----2014acm亚洲区域赛鞍山 B题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 476    Accepted Submission(s): 109 Problem Description As everyone knows, DRD has no g