招行笔试编程第二题
本地测试全都通过,提交之后通过率为0.。。。有没有大佬指点一下。
#招行笔试##招商银行##笔试题目#
bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) { return a.first < b.first; } else { return a.second < b.second; } } int main() { int T; cin >> T; while (T--) { int n; cin >> n; int tmp; vector<int> len; for (int i = 0; i < n; i++) { cin >> tmp; len.push_back(tmp); } vector<int> weight; for (int i = 0; i < n; i++) { cin >> tmp; weight.push_back(tmp); } vector<pair<int, int> > data; for (int i = 0; i < n; i++) { data.push_back(make_pair(len[i], weight[i])); } sort(data.begin(), data.end(), cmp); vector<bool> flag(n, 0); flag[0] = 1; int cnt = 0; stack<pair<int, int>> st; st.push(data[0]); while (st.size() < n) { bool start = true; for (int i = 0; i < n; i++) { if (!start) { pair<int, int> top = st.top(); if (flag[i] == 0 && data[i].first >= top.first && data[i].second >= top.second) { flag[i] = 1; st.push(data[i]); } } else { st.push(data[i]); flag[i] = 1; start = false; } } cnt++; } cout << cnt << endl; } return 0; }
#招行笔试##招商银行##笔试题目#