- 暑期集训-思维&数学
I题答疑
- @ 2026-7-11 16:05:04
I题
4 条评论
-
蒋岱均 LV 7 @ 2026-8-7 14:14:41qp
-
@ 2026-8-6 14:14:31
qp
-
@ 2026-7-11 16:09:59
先判定是否可行: 若m<n-1或m>(n+1)*2就不行 可以把0想象成隔板
然后就相当于输出一种隔板的方案: 有几个注意点: 1.若m=n-1,则方案唯一; 2.若m=2*(n+1)。也是唯一的
-
@ 2026-7-11 16:05:19#include <bits/stdc++.h> using namespace std; const int maxn=1e6+10; typedef long long ll; int n,m; int main(){ ios_base::sync_with_stdio(false); cin >> n >> m; string ans=""; int c1,c2; for(c1=n,c2=m;c1&&c2;c1--,c2-=2){ ans +="011"; } if(c2){ if(c2==1){ if(c1) cout << "01" << ans; else cout << "1"<< ans; } else if(c2==2) cout << "11" << ans; else cout << "-1"; } else if(c1){ if(c1==1) cout << ans << "0"; else cout << "-1"; } else cout << ans; return 0; }
- 1