提交时间:2023-08-25 11:00:33
运行 ID: 100305
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; scanf("%d%d",&n,&m); int a[21]; int sum = 0; int sum2 = 0; for(int i = 0;i< m;i++){ sum2 += n-i; } int cnt= 0; int cnt2 = 0; int sum3= 0; while(sum != sum2){ int flag = 0; for(int i = 1;i <= n;i++){ if(cnt2 == m){ break; }else if(cnt == 0){ printf("%d",i); a[i] = i; sum += a[i]; }else if(sum3 == sum){ if(sum-a[i-1]+i+1 != sum3 && i+1 <= n){ printf("%d",i+1); a[i] = i+1; sum += i+1; sum -= i; }else{ i--; flag++; } }else if(flag != 0){ a[i] = i+1; } cnt2++; } sum3 = sum; cnt++; } return 0; }