当前位置:网站首页>Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
2022-07-07 20:57:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
题目链接:Codeforces Round #275 (Div. 2) C – Diverse Permutation
题意:一串排列1~n。求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个。求序列、
思路:1~k+1。构造序列前段,之后直接输出剩下的数。前面的构造能够依据,两项差的绝对值为1~k构造。
AC代码:
#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;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116287.html原文链接:https://javaforall.cn
边栏推荐
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
- easyui 日期控件清空值
- How to choose financial products? Novice doesn't know anything
- 测量楼的高度
- SQL注入报错注入函数图文详解
- OneSpin | 解决IC设计中的硬件木马和安全信任问题
- Static analysis of software defects codesonar 5.2 release
- 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
- Referrer和Referrer-Policy简介
- 恶魔奶爸 A3阶段 近常速语流初接触
猜你喜欢
Klocwork 代码静态分析工具
Codesonar Webinar
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
H3C s7000/s7500e/10500 series post stack BFD detection configuration method
I Basic concepts
VMWare中虚拟机网络配置
AADL Inspector 故障树安全分析模块
Implement secondary index with Gaussian redis
Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
Apifox 接口一体化管理新神器
随机推荐
Klocwork code static analysis tool
How to meet the dual needs of security and confidentiality of medical devices?
uva 12230 – Crossing Rivers(概率)「建议收藏」
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
Micro service remote debug, nocalhost + rainbow micro service development second bullet
easyui 日期控件清空值
What are the official stock trading apps in the country? Is it safe to use
恶魔奶爸 A3阶段 近常速语流初接触
2022年在启牛开中银股票的账户安全吗?
Écrivez une liste de sauts
Nebula importer data import practice
Is it safe to open a stock account at present? Can I open an account online directly.
测量楼的高度
让这个CRMEB单商户微信商城系统火起来,太好用了!
Postgresql数据库character varying和character的区别说明
Is it safe to open an account of BOC shares in kainiu in 2022?
MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
开户还得用身份证银行卡安全吗,我是小白不懂
Phoenix JDBC
Cocos2d-x game archive [easy to understand]