ACM-ICPC 2018 徐州賽區網絡預賽 Features Track

簽到題
因爲一個小細節考慮不到wa了兩次
// 一開始沒這個if wa了。因爲數據中存在同一幀(frame)一個相同的值出現多次,這樣子同一個i 後面的同樣的特徵會把len重置爲1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
int n;
struct val
{
    int last;
    int len;
    void update(int t)
    {
        if (t == last + 1)
            ++len;
        else if (t > last + 1) // 一開始沒這個if wa了。因爲數據中存在同一幀(frame)一個相同的值出現多次,這樣子同一個i 後面的同樣的特徵會把len重置爲1
            len = 1;
        last = t;
    }
};

void work()
{
    cin >> n;
    map<pair<ll,ll>, val> m;
    int k;
    ll x,y;
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> k;
        for (int j = 0; j < k; ++j)
        {
            cin >> x >> y;
            auto it = m.find(pair<ll,ll>(x,y));
            if (it == m.end())
            {
                m[pair<ll,ll>(x,y)] = val{i,1};
                ans = max(ans,1);
            }
            else
            {
                it->second.update(i);
                ans = max(ans,it->second.len);
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while (t--)
        work();
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章