codeforces C. Diverse Permutation(构造)
Codeforces 构造 Permutation
2023-09-14 08:57:55 时间
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个
|p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素!
思路: 保证相邻的两个数的差值的绝对值为单调递减序列.....
[Codeforces 1286B] Numbers on Tree | 技巧构造 Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer ai written on it. For each vertex i, Evlampiy calculated ci the number of vertices j in the subtree of vertex i, such that a j a i
[Codeforces 1589D] Guess the Permutation | 交互 思维 二分 多组输入:{ 每组给出一个n,有一个长度为n的数列,在开始的时候a i = i ,有三个数i , j , k 数列反转了 [i,j−1] [j,k] 要求出这三个数,可以对系统进行询问 [ l , r ] 区间内 逆序对 的个数,会返回这个值
LeetCode 118:杨辉三角 II Pascal s Triangle II 公众号:爱写bug(ID:icodebugs)作者:爱写bug 给定一个非负索引 k,其中 k 33,返回杨辉三角的第 k 行。 Given a non-negative index k where k 33, return the kth index row of the Pascal s triangle. Note that the row index starts from 0. 在杨辉三角中,每个数是它左上方和右上方的数的和。
Leetcode 118:Pascal s Triangle 杨辉三角 118:Pascal s Triangle 杨辉三角 Given a non-negative integer numRows, generate the first numRows of Pascal s triangle. 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
Kubernetes 技术图谱 Kubernetes 技术图谱由 Linux Foundation 开源软件大学、马哥教育、阿里云云原生团队、阿里云开发者学堂专家联合出品,通过技术入门、Kubernetes 应知应会、Kubernetes 实践能力训练三个维度的设计,帮助云原生人才建包括理论、实践、体验的基础技能体系,提供 CKA、CKAD、ACA、ACP 等相关认证资格提供积累专业技能的基础环境。
大数据工程师进阶 技术图谱 从开源大数据技术(选学),到云上大数据快速应用(更便捷、更强大)
|p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素!
思路: 保证相邻的两个数的差值的绝对值为单调递减序列.....
如果够k个了,最后将没有访问到的元素直接添加到末尾!
#include iostream #include cstdio #include cstring #include algorithm #define N 100005 using namespace std; int vis[N]; int num[N]; int main(){ int n, k; scanf("%d%d", n, num[1] = 1; vis[1] = 1; int c = k, i; for(i=2; i ++i){ if(num[i-1]-c 0 !vis[num[i-1]-c]){ vis[num[i-1]-c]=1; num[i] = num[i-1]-c; else if(num[i-1]+c = n !vis[num[i-1]+c]){ vis[num[i-1]+c]=1; num[i] = num[i-1]+c; --c; if(c 1) break; for(int j=1; j ++j) if(!vis[j]) num[++i]=j; printf("%d", num[1]); for(int j=2; j ++j) printf(" %d", num[j]); printf("\n"); return 0; }
[Codeforces 1286B] Numbers on Tree | 技巧构造 Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer ai written on it. For each vertex i, Evlampiy calculated ci the number of vertices j in the subtree of vertex i, such that a j a i
[Codeforces 1589D] Guess the Permutation | 交互 思维 二分 多组输入:{ 每组给出一个n,有一个长度为n的数列,在开始的时候a i = i ,有三个数i , j , k 数列反转了 [i,j−1] [j,k] 要求出这三个数,可以对系统进行询问 [ l , r ] 区间内 逆序对 的个数,会返回这个值
LeetCode 118:杨辉三角 II Pascal s Triangle II 公众号:爱写bug(ID:icodebugs)作者:爱写bug 给定一个非负索引 k,其中 k 33,返回杨辉三角的第 k 行。 Given a non-negative index k where k 33, return the kth index row of the Pascal s triangle. Note that the row index starts from 0. 在杨辉三角中,每个数是它左上方和右上方的数的和。
Leetcode 118:Pascal s Triangle 杨辉三角 118:Pascal s Triangle 杨辉三角 Given a non-negative integer numRows, generate the first numRows of Pascal s triangle. 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
Kubernetes 技术图谱 Kubernetes 技术图谱由 Linux Foundation 开源软件大学、马哥教育、阿里云云原生团队、阿里云开发者学堂专家联合出品,通过技术入门、Kubernetes 应知应会、Kubernetes 实践能力训练三个维度的设计,帮助云原生人才建包括理论、实践、体验的基础技能体系,提供 CKA、CKAD、ACA、ACP 等相关认证资格提供积累专业技能的基础环境。
大数据工程师进阶 技术图谱 从开源大数据技术(选学),到云上大数据快速应用(更便捷、更强大)
相关文章
- Codeforces Round #806 (Div. 4)(A~F)
- Edu Codeforces Round 115 (Div. 2)
- Codeforces Round #674 (Div. 3)(A~D)
- Codeforces Global Round 23(A~C)
- C. Polycarp Restores PermutationCodeforces Round #547 (Div. 3)
- CodeForces 750A New Year and Hurry
- CodeForces - 999B Reversing Encryption
- A. Vova and Train ( Codeforces Round #515 (Div. 3) )