题解:CF361B Levko and Permutation
前置芝士——最大公约数 - OI Wiki
题目其实很简单,我们可以知道一些最大公约数的性质:
有一个数 xxx,则:
gcd(x,x−1)=1gcd(1,x)=1\gcd(x,x-1)=1 \\ \gcd(1,x)=1gcd(x,x−1)=1gcd(1,x)=1
那么其实只要将前 kkk 个数都往后移一位,第 kkk 位用 111 即可,后面的全是原数。
注意特判 k=nk=nk=n 和 n=1,k≠0n=1,k\ne0n=1,k=0 的情况,k=nk=nk=n 是因为第一个需要是 111,n=1,k≠0n=1,k\ne0n=1,k=0 是因为只有一个的时候一定是 000 个。
CFAC 记录:

AC code:
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int maxn=1e6+5;
int n,k;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>k;
if(k==n||n==1&&k!=0){
cout<<"-1"<<endl;
return 0;
}
for(int i=1;i<n-k;i++){
cout<<i+1<<' ';
}
cout<<1<<' ';
for(int i=n-k+1;i<=n;i++){
cout<<i<<' ';
}
return 0;
}
题解:CF361B Levko and Permutation的更多相关文章
- codeforces B. Levko and Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...
- CodeForces 361B Levko and Permutation
题意:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这个排列上的数与它所在位置的序号的最大公约数满足 > 1,并且这些数的个数恰好满足k个,输出这样的一个排 ...
- cf B. Levko and Permutation
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #includ ...
- LeetCode题解之 Letter Case Permutation
1.题目描述 2.问题分析 可以使用递归的方法解决,参考了别人的答案才写出来的. 3.代码 vector<string> letterCasePermutation(string S) { ...
- [LeetCode 题解]: Permutation Sequcence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 【题解】CF359B Permutation
[题解]CF359B Permutation 求一个长度为\(2n\)的序列,满足\(\Sigma |a_{2i}-a_{2i-1}|-|\Sigma a_{2i}-a_{2i-1}|=2k\) 这种 ...
- [LeetCode]题解(python):031-Next Permutation
题目来源 https://leetcode.com/problems/next-permutation/ Implement next permutation, which rearranges nu ...
- Lintcode388 Permutation Sequence solution 题解
[题目描述] Given n and k, return the k-th permutation sequence. Notice:n will be between 1 and 9 inclusi ...
- csps-s模拟测试62,63Graph,Permutation,Tree,Game题解
题面:https://www.cnblogs.com/Juve/articles/11631298.html permutation: 参考:https://www.cnblogs.com/clno1 ...
- Tree and Permutation (HDU 6446) 题解
// 昨天打了一场网络赛,表现特别不好,当然题目难度确实影响了发挥,但还是说明自己太菜了,以后还要多多刷题. 2018 CCPC 网络赛 I - Tree and Permutation 简单说明一下 ...
随机推荐
- 小程序uni-app处理input框将页面往上推动的解决办法
1. view <view class="bottom-wri-box" :style="{bottom: bottomHeight}"> < ...
- Linux/Centos文件授权用户文件夹权限介绍
一.Linux文件权限介绍 在Linux中,一切皆为文件(目录也是文件),每个文件对用户具有可读(read).可写(write).可执行(excute)权限.目录的执行操作表示是否有权限进入该目录并操 ...
- Codeforces 1749E Cactus Wall 题解 [ 紫 ] [ 01 BFS ] [ 图论建模 ] [ 构造 ] [ adhoc ]
一道很好的思维题,被教练碾压了. 观察 首先从题目给的样例入手: 5 5 ..... ..... ..... ..... ..... 这种情况最终的答案是: YES ....# ...#. ..#.. ...
- 2. MySQL的数据目录(详解讲解)
2. MySQL的数据目录(详解讲解) @ 目录 2. MySQL的数据目录(详解讲解) 1. MySQL8 的主要目录结构 1.1 相关命令目录 1.2 配置文件目录 2. 数据库和文件系统的关系 ...
- error setting certificate verify locations: CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt CApath: none
这个问题是因为git配置里crt证书的路径不正确导致的. 这个路径配置是在C:\Program Files\Git\etc\gitconfig中,应该所有人的配置都在这里 [diff "as ...
- 深度科普 - 大名鼎鼎的bun.js到底是什么? 它能否替代node.js? 是否能成为前端生态的未来?
什么是bun? 聪明的小伙伴们,你们在接触bun时是否有过这样的疑问呢? bun.js是什么? 它是如何诞生的? 跟node.js的区别是什么? 有什么优势? 目前的发展情况如何了? 他是否是前端的未 ...
- 试试使用 Vitest 进行测试,确实可以减少bug
vitest的简单介绍 Vitest 是一个基于 Vite 的单元测试框架,专为现代前端项目设计. 它结合了 Vite 的高性能和 Jest 的易用性, 提供了开箱即用的 TypeScript.ESM ...
- Assignment to property of function parameter 'XXX' no-param-reassign 记录
在react项目中写了一个工具方法将两个数组数据进行整合,用了双重for循环,但是在提交代码时报了eslint的no-param-reassign 结果效果是有了,但是报lint错误,图片中已是解决后 ...
- 报错:ReferenceError: __dirname is not defined in ES module scope
报错: __dirname is not defined in ES module scope 前言 新版 NodeJS 支持通过 ESM 方式导入模块,代码如: // CommonJS 规范(旧) ...
- ModuleNotFoundError: No module named '_bz2'
前言 运行 python 报错:ModuleNotFoundError: No module named '_bz2' when building python 解决 安装在 Ubuntu/Debia ...