当前位置:网站首页>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
边栏推荐
- Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
- MySQL约束之默认约束default与零填充约束zerofill
- Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
- [matrix multiplication] [noi 2012] [cogs963] random number generator
- How to meet the dual needs of security and confidentiality of medical devices?
- Nebula Importer 数据导入实践
- Spark judges that DF is empty
- 201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
- 部署、收回和删除解决方式—-STSADM和PowerShell「建议收藏」
- Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
猜你喜欢
Lex & yacc of Pisa proxy SQL parsing
如何满足医疗设备对安全性和保密性的双重需求?
Cantata9.0 | new features
Mysql子查询关键字的使用方式(exists)
Tensorflow2. How to run under x 1 Code of X
万字总结数据存储,三大知识点
Cantata9.0 | 全 新 功 能
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
随机推荐
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
MySQL约束之默认约束default与零填充约束zerofill
Static analysis of software defects codesonar 5.2 release
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
gridView自己定义做时间排版「建议收藏」
Measure the height of the building
Numerical method for solving optimal control problem (0) -- Definition
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
阿里云有奖体验:如何通过ECS挂载NAS文件系统
UVA 11080 – Place the Guards(二分图判定)
解决使用uni-app MediaError MediaError ErrorCode -5
Referrer和Referrer-Policy简介
Jetty:配置连接器[通俗易懂]
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Make this crmeb single merchant wechat mall system popular, so easy to use!
awk处理JSON处理
神兵利器——敏感文件发现工具
Can Huatai Securities achieve Commission in case of any accident? Is it safe to open an account
Phoenix JDBC
使用枚举实现英文转盲文