RE
2024-07-25 14:34:15
发布于:浙江
34阅读
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;
}
求帮助
全部评论 1
1、数组越界(i <= n 但 balls 只有 0~n-1)
2、柱子编号逻辑错误(题目是 1~n+1,你写成 0~n)
3、栈操作错误(只能移顶端,不能直接改中间)
4、变量类型混用(long long 和 int 混乱)
5、辅助柱没正确使用3天前 来自 浙江
0


有帮助,赞一个