【牛客】牛客练习赛67-D-牛妹爱数列——思维

牛牛爱字符串

https://ac.nowcoder.com/acm/contest/6885/A

D-牛妹爱数列

考虑仅进行 的翻转操作,那么对于任意一个 串,都可以通过 次翻转得到
那么这个 串长度超过 时,采用整串翻转,否则采用单个翻转

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> data;
    int tmp;
    cin >> tmp;
    data.emplace_back(tmp, 1);
    for (int i = 0; i < n - 1; ++i) {
        cin >> tmp;
        if (data.back().first == tmp) data.back().second++;
        else data.emplace_back(tmp, 1);
    }
    int re = 1;
    int ans = 0;
    for (int i = (int) data.size() - 1; i >= 0; --i) {
        if (data[i].first == re) {
            if (data[i].second >= 2) {
                re ^= 1;
            }
            ans += 1;
        }
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef ACM_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    signed localTestCount = 1, localReadPos = cin.tellg();
    char localTryReadChar;
    do {
        if (localTestCount > 20)
            throw runtime_error("Check the stdin!!!");
        auto startClockForDebug = clock();
        solve();
        auto endClockForDebug = clock();
        cout << "Test " << localTestCount << " successful" << endl;
        cerr << "Test " << localTestCount++ << " Run Time: "
             << double(endClockForDebug - startClockForDebug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (localReadPos != cin.tellg() && cin >> localTryReadChar && localTryReadChar != '$' &&
             cin.putback(localTryReadChar));
#else
    solve();
#endif
    return 0;
}
全部评论
请问任意一个1串是什么意思?
点赞 回复 分享
发布于 2020-08-14 22:24

相关推荐

不愿透露姓名的神秘牛友
08-06 11:12
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
08-05 11:30
湘潭大学 营销
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务