RE
2024-07-25 14:34:15
发布于:浙江
16阅读
0回复
0点赞
关于我这串代码是RE。
为什么啊?想来想去也没找到是哪里的问题。
求各位大佬帮我看一下是哪里出现了格式的错误等等。
崩溃了
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<vector<int>> balls(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> balls[i][j];
}
}
vector<pair<int, int>> moves;
for (int color = 0; color < m; color++) {
vector<pair<int , int>> count;
for (int i = 0; i <= n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++) {
if (balls[i][j] == color) {
cnt++;
}
}
count.push_back({cnt, i});
}
sort(count.begin(), count.end());
for (int i = 0; i < n; i++) {
if (count[i].first == 0) break;
long long from = count[i].second;
long long to = count[n].second;
moves.push_back({from + 1, to + 1});
balls[to][count[n].first - 1] = balls[from][count[i].first - 1];
balls[from][count[i].first - 1] = 0;
}
}
cout << moves.size() << endl;
for (auto move : moves) {
cout << move.first << " " << move.second << endl;
}
return 0;
}
求帮助
这里空空如也
有帮助,赞一个