当前位置:网站首页>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
边栏推荐
- Make this crmeb single merchant wechat mall system popular, so easy to use!
- 测量楼的高度
- 想杀死某个端口进程,但在服务列表中却找不到,可以之间通过命令行找到这个进程并杀死该进程,减少重启电脑和找到问题根源。
- Data sorting in string
- I Basic concepts
- 使用高斯Redis实现二级索引
- [UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
- 写一下跳表
- Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
- npm uninstall和rm直接删除的区别
猜你喜欢

Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
![[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System](/img/76/b725788272ba2dcdf866b28cbcc897.jpg)
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System

AADL Inspector 故障树安全分析模块
Klocwork code static analysis tool

The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization

最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化

Intelligent software analysis platform embold

智能软件分析平台Embold
MySQL约束之默认约束default与零填充约束zerofill

Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
随机推荐
How to meet the dual needs of security and confidentiality of medical devices?
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
HDU4876ZCC loves cards(多校题)
I Basic concepts
Micro service remote debug, nocalhost + rainbow micro service development second bullet
阿洛的烦恼
解决使用uni-app MediaError MediaError ErrorCode -5
Cantata9.0 | 全 新 功 能
ISO 26262 - 基于需求测试以外的考虑因素
Introduction to referer and referer policy
智能交通焕发勃勃生机,未来会呈现哪些巨变?[通俗易懂]
【网络原理的概念】
How to meet the dual needs of security and confidentiality of medical devices?
npm uninstall和rm直接删除的区别
使用枚举实现英文转盲文
私募基金在中國合法嗎?安全嗎?
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Spark judges that DF is empty