题解:P11007 『STA - R7』Odtlcsu

· · 题解

这道题其实很简单,因为 1 的平方和 -1 的平方都是 1,所以只需要使 1 的个数比 -1 的个数多 x,并且 1 和 -1 的个数之和为 y,即可做出

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int R() {int x = 0;bool f = 1;char ch = getchar();while (!isdigit(ch)) f = ch == '-' ? 0 : 1, ch = getchar();while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();return f ? x : -x;}//快读
const int N=6e5+10,M=1e5;
int n,m,ans,t,tt,x[N];
signed main(){
    cin>>n>>m;
    t=(m+n)/2;//1的个数
    tt=m-t;//-1的个数
    cout<<m<<endl;
    while(t--) cout<<1<<" ";
    while(tt--) cout<<-1<<" ";
    return 0;
}