当前位置:网站首页>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
边栏推荐
- 数值法求解最优控制问题(〇)——定义
- Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
- 201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
- 机械臂速成小指南(十二):逆运动学分析
- 神兵利器——敏感文件发现工具
- Phoenix JDBC
- Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- Introduction to referer and referer policy
- Update iteration summary of target detection based on deep learning (continuous update ing)
猜你喜欢
![嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]](/img/af/61b384b1b6ba46aa1a6011f8a30085.png)
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]

C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point

VMWare中虚拟机网络配置

How to meet the dual needs of security and confidentiality of medical devices?

Measure the height of the building

OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验

H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法

最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化

Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system

Mongodb learn from simple to deep
随机推荐
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
awk处理JSON处理
AADL inspector fault tree safety analysis module
【矩阵乘】【NOI 2012】【cogs963】随机数生成器
Introduction to referer and referer policy
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
恶魔奶爸 A1 语音听力初挑战
开户必须往账户里面赚钱吗,资金安全吗?
Write a jump table
Écrivez une liste de sauts
FTP steps for downloading files from Huawei CE switches
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
Cocos2d-x game archive [easy to understand]
How to meet the dual needs of security and confidentiality of medical devices?
Mysql子查询关键字的使用方式(exists)
How to choose fund products? What fund is suitable to buy in July 2022?
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
恶魔奶爸 C
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验