当前位置:网站首页>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
边栏推荐
- I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
- 【论文阅读】MAPS: Multi-agent Reinforcement Learning-based Portfolio Management System
- 反诈困境,国有大行如何破局?
- Codeforces 474 F. Ant colony
- Useful win11 tips
- H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法
- 最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
- UVA 11080 – Place the Guards(二分图判定)
- Phoenix JDBC
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
猜你喜欢

OneSpin | 解决IC设计中的硬件木马和安全信任问题
Codesonar enhances software reliability through innovative static analysis

Implement secondary index with Gaussian redis

Small guide for rapid formation of manipulator (12): inverse kinematics analysis

Apifox 接口一体化管理新神器

Measure the height of the building

CodeSonar网络研讨会

Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city

Dachang classic pointer written test questions

Codesonar Webinar
随机推荐
Intelligent software analysis platform embold
华为CE交换机下载文件FTP步骤
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
CodeSonar如何帮助无人机查找软件缺陷?
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
如何挑选基金产品?2022年7月份适合买什么基金?
AADL inspector fault tree safety analysis module
部署、收回和删除解决方式—-STSADM和PowerShell「建议收藏」
Make this crmeb single merchant wechat mall system popular, so easy to use!
恶魔奶爸 B3 少量泛读,完成两万词汇量+
Écrivez une liste de sauts
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
uva 12230 – Crossing Rivers(概率)「建议收藏」
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
【奖励公示】第22期 2022年6月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
私募基金在中国合法吗?安全吗?
现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?