Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)C

题目链接C. Maximum splitting
题意:问你一个数最多由几个和数构成,不能输出-1.
题解:最小和数是4最小的奇和数是9,显然1,2,3,不能,如果这个数p为偶数,那答案应该为p/4,因为如果p能被4整除答案显然,如果不能我们可以把余下的2与4相加为6代替,
如果为奇数且大与9,可以用这个数减去9,余下的就是偶数处理同偶数。小于9的奇数显然不可以。

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#define pb push_back
#define ll long long
#define PI 3.14159265
using namespace std;
const int maxn=1e5+5;
int n,m;
int p;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>p;
		if(p<=3)
		{
			cout<<-1<<'
';
			continue;
		}
		else
		{
			if(p%2==0)
			{
				cout<<p/4<<'
'; 
			}
			else
			{
				if(p>=9)
				{
					p-=9;
					if(p<4&&p)
					{
						cout<<-1<<'
';
					}
					else
					{
						cout<<p/4+1<<'
'; 
					}
				}
				else
				{
					cout<<-1<<'
';
				}
			}
		}
	}
	
	return 0;
 } 
原文地址:https://www.cnblogs.com/lhclqslove/p/7684360.html