链接:
https://codeforces.com/problemset/problem/1352/B
题意:
求n能不能由k个奇数或者k个偶数组成
输入
8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9
输出量
YES
4 2 4
YES
55 5 5 35
NO
NO
YES
1 1 1 1 1 1 1 1
NO
YES
3 1 1
YES
111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120
解:
先来k-1个1或者k-1个2,然后判断剩下的数字是否为正和奇偶性
实际代码:
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
for(int f=1;f<=t;f++)
{
int n,k;
cin>>n>>k;
int jsum=k-1;
int osum=2*(k-1);
bool ans=0;
if(n-jsum>0&&(n-jsum)%2!=0) ans=1;
if(n-osum>0&&(n-osum)%2==0) ans=1;
if(ans)
{
cout<<"YES"<<endl;
if(n-jsum>0&&(n-jsum)%2!=0)
{
for(int i=1;i<k;i++)
{
cout<<1<<" ";
}
cout<<n-jsum<<endl;
}
else if(n-osum>0&&(n-osum)%2==0)
{
for(int i=1;i<k;i++)
{
cout<<2<<" ";
}
cout<<n-osum<<endl;
}
}
else cout<<"NO"<<endl;
}
}
限制:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output