A116128.皓仔的彩旗布置 题解
2026-07-26 18:25:45
发布于:北京
4阅读
0回复
0点赞
A116128.皓仔的彩旗布置 题解
一、题目解释
题目可以转化为这样的问题:有n个数,做m次变换,输出变换后的结果。
二、思路
可以用数组存储n个数,起初都是0,每次对输入的x和c进行此操作:“arr[x] = c;”表示对编号为x的旗帜更换为数值c。
三、代码
#include<bits/stdc++.h>
using namespace std;
int n, m, x, c, a[1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
while (m--) {
cin >> x >> c;
a[x] = c;
}
for (int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
时间复杂度为O(n)可以通过
这里空空如也


有帮助,赞一个