题目链接:http://codeforces.com/contest/872/problem/C

题意:

  给你一个数n,问你最多能将n分解成多少个合数之和。(若不能分解,输出-1)

题解:

  若要让合数个数最多,则n必定只由4,6,9组成。

  n由n/4和n%4两部分组成。

  四种情况:

    (1)n%4 == 0:

      全分成4就好了,所以ans = n/4

    (2)n%4 == 1:

      剩下的1要和两个4组合成一个9。

      所以如果n/4 >= 2,ans = n/4 - 1

      否则ans = -1

    (3)n%4 == 2:

      剩下的2要和一个4组合成一个6。

      所以如果n/4 >= 1,ans = n/4

      否则ans = -1

    (4)n%4 == 3:

      剩下的3 = 1 + 2。所以需要三个4,组成一个6和一个9。

      所以如果n/4 >= 3,ans = n/4 - 1

AC Code:

 #include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; int n,t; int main()
{
cin>>t;
while(t--)
{
cin>>n;
if(n%==) cout<<n/<<endl;
else if(n%==)
{
if(n/>=) cout<<n/<<endl;
else cout<<-<<endl;
}
else if(n%==)
{
if(n/>=) cout<<n/-<<endl;
else cout<<-<<endl;
}
else
{
if(n/>=) cout<<n/-<<endl;
else cout<<-<<endl;
}
}
}

Codeforces 872C Maximum splitting:数学【分解成合数之和】的更多相关文章

  1. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  2. CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)

    B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】

    C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

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

    地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Maximum splitting(规律,数论)

    You are given several queries. In the i-th query you are given a single positive integer ni. You are ...

  6. Maximum splitting

    Maximum splitting You are given several queries. In the i-th query you are given a single positive i ...

  7. 萌新笔记——C++里将string类字符串(utf-8编码)分解成单个字(可中英混输)

    最近在建词典,使用Trie字典树,需要把字符串分解成单个字.由于传入的字符串中可能包含中文或者英文,它们的字节数并不相同.一开始天真地认为中文就是两个字节,于是很happy地直接判断当前位置的字符的A ...

  8. 百度在线笔试编程测试题(Python):整数分解成素数的积

    编程测试题: 输入一个正整数将其分解成素数的乘积,输入格式连续输入m个数,然后将这m个数分别分解,如 输入: 2 10 20 输出: 2 5 2 2 5 Python code: def primes ...

  9. 使用List把一个长字符串分解成若干个短字符串

    把一个长字符串分解成若干个固定长度的短字符串,由于事先不知道长字符串的长度,以及短字符串的数量,只能使用List. public static void get_list_sbody(String s ...

随机推荐

  1. 对于Json和对象转换的学习

    学习这个的用处有非常多的:        在传输数据过程中比較查看数据比較清晰,代码也较清晰.也能够避免split函数带来的隐藏bug 当然也有不足:        准备工具较繁琐,须要准备对象(当然 ...

  2. Android · SQLiteOpenHelper实例PrivateContactsDBHelper

    package privatecontact; import android.content.ContentValues; import android.content.Context; import ...

  3. 事件绑定,事件捕获,事件冒泡以及事件委托,兼容IE

    ● 事件分为三个阶段:   事件捕获 -->  事件目标 -->  事件冒泡 ● 事件捕获:事件发生时(onclick,onmouseover……)首先发生在document上,然后依次传 ...

  4. winform 下载文件显示进度和百分比

    /// <summary> /// 下载完成 /// </summary> private void DownloadFileCompleted() { IsComlate = ...

  5. 使用Apache Benchmark做压力测试遇上的5个常见问题

    这一篇文章主要记录我在使用Apache Benchmark(一下检测ab)做网站压力测试的过程中,遇到的一些问题以及解决办法,方便日后使用. 这一篇文章主要记录我在使用Apache Benchmark ...

  6. apache common包 CollectionUtils 使用 详解

    集合判断:  例1: 判断集合是否为空: CollectionUtils.isEmpty(null): true CollectionUtils.isEmpty(new ArrayList()): t ...

  7. eclipse adt开发android ndk没有NDK选项问题的解决方案

    原创 2015年01月28日 09:38:40 标签: android ndk / eclipse / adt 15989 今天是2015年1月28号,整理一下昨天使用eclipse adt搭建的an ...

  8. Java的Executor框架和线程池实现原理

    Java的Executor框架 1,Executor接口 public interface Executor { void execute(Runnable command); } Executor接 ...

  9. 华为AI应用创新大赛即将开启!公开课已备好!

    为鼓励开发者创新,挖掘前沿创新能力的应用及服务,帮开发者打造爆款应用的同时丰富终端消费者的用户体验,由设立10亿激励基金耀星计划扶持的华为创新竞赛平台即将开启. 竞赛平台将滚动推出AI.HAG.AR. ...

  10. java和erlang之间的DES加解密

    app登录,登录的密码要用DES加密,服务器是用erlang,客户端要同时支持多平台(Android.iOS).首先,Java端的DES加密的实现方式, 少说废话了,直接上代码,如下: public ...