当前位置:网站首页>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
边栏推荐
- Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
- Data sorting in string
- MySQL约束之默认约束default与零填充约束zerofill
- Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
- 私募基金在中国合法吗?安全吗?
- Cocos2d-x 游戏存档[通俗易懂]
- 想杀死某个端口进程,但在服务列表中却找不到,可以之间通过命令行找到这个进程并杀死该进程,减少重启电脑和找到问题根源。
- Cantata9.0 | new features
- 开户还得用身份证银行卡安全吗,我是小白不懂
- 【C语言】指针进阶---指针你真的学懂了吗?
猜你喜欢
万字总结数据存储,三大知识点
CodeSonar网络研讨会
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
Dachang classic pointer written test questions
Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
MySQL约束之默认约束default与零填充约束zerofill
解决使用uni-app MediaError MediaError ErrorCode -5
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
Klocwork 代码静态分析工具
Mysql子查询关键字的使用方式(exists)
随机推荐
Nebula importer data import practice
恶魔奶爸 B3 少量泛读,完成两万词汇量+
sqlHelper的增删改查
2022年在启牛开中银股票的账户安全吗?
Mongodb learn from simple to deep
目标:不排斥 yaml 语法。争取快速上手
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
CodeSonar网络研讨会
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
Is it safe to open an account of BOC shares in kainiu in 2022?
object-c编程tips-timer「建议收藏」
Deep learning model compression and acceleration technology (VII): mixed mode
Mahout-Pearson correlation的实现
浅解ARC中的 __bridge、__bridge_retained和__bridge_transfer
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
写一下跳表
Cocos2d-x game archive [easy to understand]
【奖励公示】第22期 2022年6月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖