题目链接: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. AutoCAD2004启动时出现fail to get CommcntrController的怎么办

    解决AutoCAD2004启动时出现fail to get CommcntrController的问题! 2009-02-01 18:06 以前安装AutoCAD2004的时候可以用正常使用,后来又装 ...

  2. apue学习笔记(第十七章 高级进程间通信)

    本章介绍一种高级IPC---UNIX域套接字机制,并说明它的应用方法 UNIX域套接字 UNIX域套接字用于在同一台计算机上运行的进程(无关进程)之间的(全双工)通信.相比于因特网套接字,UNIX域套 ...

  3. Material Design Get Started

    使用Material Design设计应用: Take a look at the material design specification. Apply the material theme to ...

  4. 【原创】基于.NET的轻量级高性能 ORM - TZM.XFramework

    [前言] 接上一篇<[原创]打造基于Dapper的数据访问层>,Dapper在应付多表自由关联.分组查询.匿名查询等应用场景时不免显得吃力,经常要手写SQL语句(或者用工具生成SQL配置文 ...

  5. Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]

    题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...

  6. mysql 让一个存储过程定时作业的代码(转)

    1.在mysql 中建立一个数据库 test1 语句:create database test1 2.创建表examinfo create table examinfo( id int auto_in ...

  7. python读写数据篇

    一.读写数据1.读数据 #使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件.file_object = open('thefi ...

  8. python跳坑手记

    解决python同目录报错:import util 改成 from . import util

  9. VS2017快捷键

    1.回到上一个光标位置/前进到下一个光标位置 (1)回到上一个光标位置:使用组合键“Ctrl + -”; (2)前进到下一个光标位置:“Ctrl + Shift + - ”. 2.复制/剪切/删除整行 ...

  10. 九度OJ 1033:继续xxx定律 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4987 解决:1201 题目描述:     当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...