当前位置:网站首页>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
边栏推荐
- SQL注入报错注入函数图文详解
- Mahout-Pearson correlation的实现
- OneSpin | 解决IC设计中的硬件木马和安全信任问题
- 万字总结数据存储,三大知识点
- 嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
- Spark 判断DF为空
- MySQL storage expression error
- [UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
- CodeSonar如何帮助无人机查找软件缺陷?
- [matrix multiplication] [noi 2012] [cogs963] random number generator
猜你喜欢
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
使用枚举实现英文转盲文
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
H3C s7000/s7500e/10500 series post stack BFD detection configuration method
使用高斯Redis实现二级索引
Klocwork 代码静态分析工具
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
Klocwork code static analysis tool
Lex & yacc of Pisa proxy SQL parsing
AADL inspector fault tree safety analysis module
随机推荐
私募基金在中国合法吗?安全吗?
恶魔奶爸 B3 少量泛读,完成两万词汇量+
Dachang classic pointer written test questions
object-c编程tips-timer「建议收藏」
【网络原理的概念】
How does codesonar help UAVs find software defects?
Klocwork code static analysis tool
Is private equity legal in China? Is it safe?
Tensorflow2. How to run under x 1 Code of X
Alibaba cloud award winning experience: how to mount NAS file system through ECS
测量楼的高度
Solve the problem that the executable file of /bin/sh container is not found
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
gridView自己定义做时间排版「建议收藏」
Apifox interface integrated management new artifact
Nebula importer data import practice
Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
解决使用uni-app MediaError MediaError ErrorCode -5
现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
Is it safe to open an account online now? I want to know where I can open an account in Nanning now?