E. Klever Permutation
1.B. Rudolf and 1212.C. Rudolf and the Ugly String3.A. Rudolf and the Ticket4.D. Rudolf and the Ball Game5.G. Rudolf and Subway6.C. Choose the Different Ones!7.B. Following the String
8.E. Klever Permutation
9.D. Find the Different Ones!10.B. YetnotherrokenKeoard11.C. Removal of Unattractive Pairs12.D. Jumping Through Segments13.E. Good Triples14.F. Shift and Reverse15.C. Nikita and LCM16.B. Prefiquence17.E. Vlad and a Pair of Numbers18.D. XOR Construction19.C. Non-coprime Split20.D. Divide and Equalize21.E. Block Sequence22.D. In Love23.C. Theofanis' Nightmare24.D. Yet Another Monster Fight25.C. Count Triangles26.E. Count Paths27.Collecting Numbers II28.C. Even Subarrays29.C. Perform Operations to Maximize Score30.F. Color Rows and Columns31.C. To Become Max题解
假设 a1 a2 a3 ... ak ak+1 ak+2 ... an是符合要求的数组,
那么我们可以推断出:
a(k+1)=a(1)+1;
a(k+2)=a(2)-1;
...
a(2k+1)=a(k+1)+1;
...
因此我们知晓奇数位的数要比较小,偶数的位置要比较大;又题目说明一定有解,所以我们假定a1=1,a2=n再递推出其余各项。
Code
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int a[N]; int main(){ ios::sync_with_stdio(false); int t; cin>>t; while (t--){ int n,k,cnt=-1; cin>>n>>k; int sum1=n,sum2=1; for (int i=1;i<=k;i++){ for (int j=i;j<=n;j+=k) if (i%2==1) a[j]=sum1--; else a[j]=sum2++; } for (int i=1;i<=n;i++) if (i==1) cout<<a[i]; else cout<<" "<<a[i]; cout<<endl; } return 0; }
合集:
codeforces
分类:
刷题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】