Codeforces 872C Maximum splitting:数学【分解成合数之和】
题目链接: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:数学【分解成合数之和】的更多相关文章
- Codeforces 870C Maximum splitting (贪心+找规律)
<题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...
- CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)
B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】
C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- Maximum splitting(规律,数论)
You are given several queries. In the i-th query you are given a single positive integer ni. You are ...
- Maximum splitting
Maximum splitting You are given several queries. In the i-th query you are given a single positive i ...
- 萌新笔记——C++里将string类字符串(utf-8编码)分解成单个字(可中英混输)
最近在建词典,使用Trie字典树,需要把字符串分解成单个字.由于传入的字符串中可能包含中文或者英文,它们的字节数并不相同.一开始天真地认为中文就是两个字节,于是很happy地直接判断当前位置的字符的A ...
- 百度在线笔试编程测试题(Python):整数分解成素数的积
编程测试题: 输入一个正整数将其分解成素数的乘积,输入格式连续输入m个数,然后将这m个数分别分解,如 输入: 2 10 20 输出: 2 5 2 2 5 Python code: def primes ...
- 使用List把一个长字符串分解成若干个短字符串
把一个长字符串分解成若干个固定长度的短字符串,由于事先不知道长字符串的长度,以及短字符串的数量,只能使用List. public static void get_list_sbody(String s ...
随机推荐
- 关于insert|update|delete注入中的tips
2.updatexml().extractvalue().name_const()函数的使用 3.I’ve noticed some variations in our payload. You ca ...
- Php网站如何优化才好?
尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非 ...
- vue2.0 仿手机新闻站(二)项目结构搭建 及 路由配置
1.项目结构 $ vue init webpack-simple news $ npm install vuex vue-router axios style-loader css-loader -D ...
- Shell脚本之:替换
转义字符 #!/bin/bash a= echo -e "Value of a is $a \n" 使用-e表示对转义字符进行替换,默认情况是不转义的 命令替换 命令替换的语法,注 ...
- mixare的measureText方法在频繁调用时抛出“referencetable overflow max 1024”的解决方式
这几天在搞基于位置的AR应用,採用了github上两款开源项目: mixare android-argument-reality-framework 这两个项目实现机制大致同样.我选取的是androi ...
- Linux安装indicator-china-weather
https://launchpad.net/indicator-china-weather sudo apt-get update sudo apt-get install python-appind ...
- 导出txt格式的说明书
/// <summary> /// 说明书 /// </summary> /// <returns></returns> public FileResu ...
- html中图片上传预览的实现
本地图片预览 第一种方法 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type& ...
- web 表单方式上传文件方法(不用flash插件)
原理:使用表单的input type="file"标签,通过ajax提交表单请求,后台获取请求中的文件信息,进行文件保存操作 由于我测试用的做了一个上传文件和上传图片方法,所以我有 ...
- Struts2学习九----------处理结果类型(input)
© 版权声明:本文为博主原创文章,转载请注明出处 Struts2处理结果类型 - SUCCESS:Action正确的执行完成,返回相应的视图,success是name属性的默认值 - ERROR:表示 ...