当前位置:网站首页>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
边栏推荐
- 开户还得用身份证银行卡安全吗,我是小白不懂
- Dachang classic pointer written test questions
- 想杀死某个端口进程,但在服务列表中却找不到,可以之间通过命令行找到这个进程并杀死该进程,减少重启电脑和找到问题根源。
- MySQL storage expression error
- 智能软件分析平台Embold
- 【函数递归】简单递归的5个经典例子,你都会吗?
- [UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
- Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
- Mysql子查询关键字的使用方式(exists)
- 使用高斯Redis实现二级索引
猜你喜欢

C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)

95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全

Make this crmeb single merchant wechat mall system popular, so easy to use!

解决使用uni-app MediaError MediaError ErrorCode -5

Tensorflow2. How to run under x 1 Code of X
Mysql子查询关键字的使用方式(exists)

Codesonar Webinar

不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
Codesonar enhances software reliability through innovative static analysis

Implement secondary index with Gaussian redis
随机推荐
201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
Spark 判断DF为空
如何满足医疗设备对安全性和保密性的双重需求?
[function recursion] do you know all five classic examples of simple recursion?
Introduction to referer and referer policy
[UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
恶魔奶爸 A0 英文零基础的自我提升路
智能交通焕发勃勃生机,未来会呈现哪些巨变?[通俗易懂]
Cocos2d-x game archive [easy to understand]
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
Phoenix JDBC
Measure the height of the building
MySQL storage expression error
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
Make this crmeb single merchant wechat mall system popular, so easy to use!
Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
Cantata9.0 | new features