1352B - Same Parity Summands

链接:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值