当前位置:网站首页>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
边栏推荐
猜你喜欢

ISO 26262 - 基于需求测试以外的考虑因素

使用高斯Redis实现二级索引

Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system

Make this crmeb single merchant wechat mall system popular, so easy to use!
Codesonar enhances software reliability through innovative static analysis

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

Nebula Importer 数据导入实践

Apifox 接口一体化管理新神器
CodeSonar通过创新型静态分析增强软件可靠性

I Basic concepts
随机推荐
私募基金在中國合法嗎?安全嗎?
201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
寫一下跳錶
Measure the height of the building
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Dachang classic pointer written test questions
Écrivez une liste de sauts
object-c编程tips-timer「建议收藏」
Phoenix JDBC
[matrix multiplication] [noi 2012] [cogs963] random number generator
使用高斯Redis实现二级索引
数值法求解最优控制问题(〇)——定义
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
I Basic concepts
You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
【矩阵乘】【NOI 2012】【cogs963】随机数生成器