当前位置:网站首页>Codeforces round 275 (Div. 2) C – diverse permutation (construction) [easy to understand]
Codeforces round 275 (Div. 2) C – diverse permutation (construction) [easy to understand]
2022-07-07 21:00:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Topic link :Codeforces Round #275 (Div. 2) C – Diverse Permutation
The question : A string of 1~n. Find the number of absolute values of the difference between two adjacent terms in a sequence ( The number of different absolute values ) by k individual . Find sequence 、
Ideas :1~k+1. Construction sequence front segment , Then directly output the remaining number . The previous structure can be based on , The absolute value of the difference between the two terms is 1~k structure .
AC Code :
#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;
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116287.html Link to the original text :https://javaforall.cn
边栏推荐
- 神兵利器——敏感文件发现工具
- HOJ 2245 浮游三角胞(数学啊 )
- Nebula importer data import practice
- margin 等高布局
- CodeSonar通过创新型静态分析增强软件可靠性
- Implement secondary index with Gaussian redis
- Codesonar enhances software reliability through innovative static analysis
- Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
- 浅解ARC中的 __bridge、__bridge_retained和__bridge_transfer
- UVA 11080 – Place the Guards(二分图判定)
猜你喜欢

CodeSonar网络研讨会

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

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

智能软件分析平台Embold

目标:不排斥 yaml 语法。争取快速上手

Measure the height of the building

How does codesonar help UAVs find software defects?

CodeSonar如何帮助无人机查找软件缺陷?

Small guide for rapid formation of manipulator (12): inverse kinematics analysis
Codesonar enhances software reliability through innovative static analysis
随机推荐
Differences and connections between MinGW, mingw-w64, tdm-gcc and other tool chains "suggestions collection"
Klocwork 代码静态分析工具
Intelligent software analysis platform embold
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Phoenix JDBC
Can Huatai Securities achieve Commission in case of any accident? Is it safe to open an account
死锁的产生条件和预防处理[通俗易懂]
Validutil, "Rethinking the setting of semi supervised learning on graphs"
ISO 26262 - 基于需求测试以外的考虑因素
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
阿洛的烦恼
Codeforces 474 F. Ant colony
恶魔奶爸 A0 英文零基础的自我提升路
Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
Alibaba cloud award winning experience: how to mount NAS file system through ECS
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
OneSpin | 解决IC设计中的硬件木马和安全信任问题
Codesonar Webinar
2022年在启牛开中银股票的账户安全吗?