首页 > TAG信息列表 > 1762

AcWing 1762. 牛的洗牌(暴力)

题目链接 https://www.acwing.com/problem/content/1764/ 思路 因为我们要做三次它的排序,那么我们初始状态的话每个位置上的编号就是本身,然后我们定义一个b数组表示的是最后排出的结果,那么每次我们更新b数组的值的时候需要用到我们上一个状态的值,所以我们定义一个c数组存储b

1762. Buildings With an Ocean View

My first solution is use two skacks, one stack store index, another one store value, the time complexity is O(n). public int[] findBuildings(int[] heights) { Stack<Integer> indexStk = new Stack<>(); Stack<Integer> va

AcWing 1762. 牛的洗牌

文章目录 题目思考代码算法 题目 思考 题目可以这么描述: 有 n n n个数(即题目中奶牛的 I D

AcWing 1762. 牛的洗牌

思路:暴力逆推3次,我们发现上一轮和本轮的关系是preid[i]=id[a[i]] 代码: #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 110; int a[N],id[N]; int main() { int n; cin>>n; for(int i=1;i<=n;i++)