当前位置:网站首页>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
边栏推荐
- Mahout-Pearson correlation的实现
- What are the official stock trading apps in the country? Is it safe to use
- Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
- Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
- 使用高斯Redis实现二级索引
- uva 12230 – Crossing Rivers(概率)「建议收藏」
- 如何挑选基金产品?2022年7月份适合买什么基金?
- Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
- 凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
- MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
猜你喜欢

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

I Basic concepts

神兵利器——敏感文件发现工具

Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city

Nebula Importer 数据导入实践

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

程序猿赚的那点钱算个P啊!

Tensorflow2.x下如何运行1.x的代码

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?
随机推荐
Implement secondary index with Gaussian redis
Phoenix JDBC
刚开户的能买什么股票呢?炒股账户安全吗
恶魔奶爸 A3阶段 近常速语流初接触
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
Introduction to referer and referer policy
如何挑选基金产品?2022年7月份适合买什么基金?
201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
阿洛的烦恼
恶魔奶爸 B3 少量泛读,完成两万词汇量+
CodeSonar通过创新型静态分析增强软件可靠性
H3C s7000/s7500e/10500 series post stack BFD detection configuration method
Apifox 接口一体化管理新神器
CodeSonar网络研讨会
Jetty:配置连接器[通俗易懂]
Implement secondary index with Gaussian redis
Codeforces Round #275 (Div. 2) C – Diverse Permutation (构造)[通俗易懂]
Static analysis of software defects codesonar 5.2 release
Écrivez une liste de sauts
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System