2010 杭州赛区 1005 Code Management System

这几次比赛由于没有太好的解题策略,以至于我们队把这个水题给放走了,大部分时间都在改计算几何,到最后也没有 AC。

这题不想说什么,很大自然的题目,就是模拟,用各种 STL 来模拟,我考虑到既然模拟了,应该不会超时吧?今天就拍了下,果断 1Y,这么暴力的方法 600 多 ms 过。

嗯,主要是记录每个人最近一次下载代码的时间,每行更新的时间和优先级,每个人的优先级。

懒得 hash 了,直接 map 做。

对于 submit 操作,之前 modify 的行号全部放到一个 list 中,submit 的时候直接清空链表就可以了。。。

嗯,很长的代码,不过看上去比计算几何会好很多。。。

这题还有一个比较不好处理的是字符串的手动分割,这种题目我平时还是做比较多了,直接数长度就可以了,谁叫这题的输入格式这么的。。。呵呵呵呵。。。

我的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <map>
#include <string>
#include <vector>

using namespace std;

struct Time {
int y, m, d;
int hh, mm, ss;
Time();
Time(char* s);
bool operator<(const Time& t) const;
Time operator=(const Time& t);
void Show();
};
struct Node {
int level;
string name;
Time t;
};

struct In {
string name;
int id;
Time t;
bool operator<(const In& in) const;
};

map<string, list<int> > mod;
map<string, int> level;
map<int, Node> last;
map<int, Node>::iterator res;
map<string, Time> sub;
vector<In> in;
vector<In>::iterator itin;

void init();

int main() {
int n, m, num;
In data;
char str[150], op[150];
string name;
while (scanf("%d", &n), n) {
init();
for (int i = 0; i < n; i++) {
scanf("%s%d%d", str, &num, &m);
name = str;
level[name] = num;
data.name = name;
gets(str);
for (int j = 0; j < m; j++) {
gets(op);
for (int k = 0; k < 21; k++) str[k] = op[k];
str[21] = 0;
data.t = Time(str);
switch (op[23]) {
case 'Y':
case 'U':
data.id = -1;
break;
case 'O':
int k = 29;
data.id = 0;
while (op[k]) {
data.id = data.id * 10 + op[k] - '0';
k++;
}
break;
}
in.push_back(data);
}
}
sort(in.begin(), in.end());
for (itin = in.begin(); itin != in.end(); itin++) {
//(itin->t).Show(); //printf(" %s %d\n",(itin->name).c_str(),itin->id);
list<int>& lst = mod[itin->name];
if (itin->id == -1) {
while (!lst.empty()) {
num = lst.front();
lst.pop_front();
if (last.find(num) == last.end() ||
last[num].level < level[itin->name] ||
last[num].t < sub[itin->name]) {
last[num].t = itin->t;
last[num].level = level[itin->name];
last[num].name = itin->name;
}
}
sub[itin->name] = itin->t;
} else {
lst.push_back(itin->id);
}
}
for (res = last.begin(); res != last.end(); res++) {
printf("%d ", res->first);
(res->second).t.Show();
printf(" BY %s\n", (res->second).name.c_str());
}
puts("END");
}
return 0;
}

Time::Time() {
y = m = d = 0;
hh = mm = ss = 0;
}

Time::Time(char* s) {
sscanf(s, "[%d/%d/%d%d:%d:%d]", &y, &m, &d, &hh, &mm, &ss);
}

bool Time::operator<(const Time& t) const {
if (y != t.y)
return y < t.y;
else if (m != t.m)
return m < t.m;
else if (d != t.d)
return d < t.d;
else if (hh != t.hh)
return hh < t.hh;
else if (mm != t.mm)
return mm < t.mm;
else
return ss < t.ss;
}

Time Time::operator=(const Time& t) {
y = t.y;
m = t.m;
d = t.d;
hh = t.hh;
mm = t.mm;
ss = t.ss;
return *this;
}

bool In::operator<(const In& in) const { return t < in.t; }

void Time::Show() {
printf("[%04d/%02d/%02d %02d:%02d:%02d]", y, m, d, hh, mm, ss);
}

void init() {
mod.clear();
in.clear();
level.clear();
last.clear();
sub.clear();
}

剩下的还有几场比赛要加油了,今晚的 Code Forces 应该可以再去混混。。。