跳到正文

Pura_30

1384503

这个家伙很勤劳,写了“这个家伙很勤劳,写了这个家伙很勤劳,写了“这个家伙很勤劳,写了这个家伙很勤劳,写了“这个家伙很勤劳,写了这个家伙很勤劳,写了“这个家伙很勤劳,写了(循环输出过长,代码自动结束)

在洛谷打开
资料、奖项与版本

资料

编号
1384503
抓取

进入记事本内食用源代码更佳


代码
  |       |
((((((((((||)))))))))\
((((((((((||)))))))))||============----
((((((((((||)))))))))/        

#include <bits/stdc++.h> using namespace std;

int n, m; string res; vector<pair<int, int>> con;

bool is_afo(int ind) { for (const auto& p : con) { int sta = p.first; int end = p.second; if (ind == end) { bool fou = false; for (int k = sta; k < ind; ++k) { if (res[k] == ‘A’) { fou = true; break; } } if (!fou) { return true; } } } return false; }

bool sea(int ind, int a_cn, int ite) { int b_cn = ind - a_cn; if (a_cn > n / 2 || b_cn > n / 2) { return false; } if (ind == n) { return ite == 0; } bool for_a = is_afo(ind); if (for_a) { if (a_cn >= n / 2) { return false; } res[ind] = ‘A’; return sea(ind + 1, a_cn + 1, ite + 1); } else { if (a_cn < n / 2) { res[ind] = ‘A’; if (sea(ind + 1, a_cn + 1, ite + 1)) { return true; } } if (b_cn < n / 2 && ite > 0) { res[ind] = ‘B’; if (sea(ind + 1, a_cn, ite - 1)) { return true; } } } return false; }

void sol() { cin >> n >> m; con.assign(m, {}); for (int i = 0; i < m; ++i) { cin >> con[i].first >> con[i].second; con[i].first—; con[i].second—; } res.assign(n, ’ ’); if (sea(0, 0, 0)) { cout << res << endl; } else { cout << -1 << endl; } }

int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t—) { sol(); } return 0; }

还没有收录这位用户的文章。