【避坑】从0到100的debug(不是去重)
查看原帖
【避坑】从0到100的debug(不是去重)
399493
Smiog楼主2023/8/4 18:05

对于每个测试点的 mm 个询问 Q1,Q2,…,Qm,Q_1,Q_2,\dots ,Q_m, ∃a,b∈[1,m],Qa=Qb.\exists a,b\in [1,m],Q_a=Q_b.


那么根据如上性质,我写出的第一份代码(map<string,queue>实现)惨遭爆零↓

cin >> str;
int tmp = 0;
while (!mp[str].empty())
{
    if (mp[str].front() != tmp)
        printf("%d ", mp[str].front());
    tmp = mp[str].front();
    mp[str].pop();
}
puts("");

然后我傻傻地根据题解把去重改成了数组标记,继续爆零↓

for (int i = 0; i ^ 1005; ++i)
    vis[i] = 0;
cin >> str;
while (!mp[str].empty())
{
    if (!vis[mp[str].front()])
    {
        printf("%d ", mp[str].front());
        vis[mp[str].front()] = 1;
    }
    mp[str].pop();
}
puts("");

看到WA反馈一直是“too short on line xx”,才发现问题,AC代码(改用map<string,vector>实现)↓

for (int i = 0; i ^ 1005; ++i)
    vis[i] = 0;
cin >> str;
for (int i = 0; i ^ mp[str].size(); ++i)
    if (!vis[mp[str][i]])
    {
        printf("%d ", mp[str][i]);
        vis[mp[str][i]] = 1;
    }
puts("");

可能这个错误在某些dalao眼里无比低级,但肯定有人因此爆零 比如我,所以勿喷谢谢。

2023/8/4 18:05
加载中...