当前位置:网站首页>Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
2022-07-07 20:57:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
题目链接:Codeforces Round #275 (Div. 2) C – Diverse Permutation
题意:一串排列1~n。求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个。求序列、
思路:1~k+1。构造序列前段,之后直接输出剩下的数。前面的构造能够依据,两项差的绝对值为1~k构造。
AC代码:
#include <stdio.h>
#include <string.h>
int ans[200010];
bool vis[100010];
int n,mark;
int iabs(int a)
{
if(a<0) return -a;
return a;
}
int main()
{
int i,cnt,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
int x,y;
memset(vis,0,sizeof vis);
ans[0]=1;
x=1,y=k+1;
cnt=k;
for(i=1; i<=k; i++,cnt--)
{
int temp=ans[i-1]+cnt;
if(temp>k+1)
temp=ans[i-1]-cnt;
else if(vis[temp])
temp=ans[i-1]-cnt;
ans[i]=temp;
vis[temp]=true;
}
for(i=k+1; i<n; i++)
ans[i]=i+1;
for(i=0; i<n-1; i++)
printf("%d ",ans[i]);
printf("%d\n",ans[i]);
}
return 0;
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116287.html原文链接:https://javaforall.cn
边栏推荐
- Apifox 接口一体化管理新神器
- Update iteration summary of target detection based on deep learning (continuous update ing)
- Dachang classic pointer written test questions
- Phoenix JDBC
- 【奖励公示】第22期 2022年6月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
- 神兵利器——敏感文件发现工具
- Make this crmeb single merchant wechat mall system popular, so easy to use!
- Intelligent software analysis platform embold
- Nebula importer data import practice
- Mysql子查询关键字的使用方式(exists)
猜你喜欢

Nebula importer data import practice

机械臂速成小指南(十一):坐标系的标准命名

Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
![[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System](/img/76/b725788272ba2dcdf866b28cbcc897.jpg)
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System

Intelligent software analysis platform embold

【C语言】指针进阶---指针你真的学懂了吗?

解决使用uni-app MediaError MediaError ErrorCode -5
Mysql子查询关键字的使用方式(exists)

Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
随机推荐
Write a jump table
UVA 11080 – Place the Guards(二分图判定)
Deep learning model compression and acceleration technology (VII): mixed mode
Implement secondary index with Gaussian redis
guava多线程,futurecallback线程调用不平均
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Flask1.1.4 Werkzeug1.0.1 源码分析:路由
现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
恶魔奶爸 A3阶段 近常速语流初接触
You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
机械臂速成小指南(十二):逆运动学分析
Codeforces 474 F. Ant colony
如何满足医疗设备对安全性和保密性的双重需求?
目标:不排斥 yaml 语法。争取快速上手
ISO 26262 - 基于需求测试以外的考虑因素
万字总结数据存储,三大知识点
Solve the problem that the executable file of /bin/sh container is not found
CodeSonar通过创新型静态分析增强软件可靠性
寫一下跳錶