CodeForces 669A
链接:http://codeforces.com/problemset/problem/669/A
本文链接:http://www.cnblogs.com/Ash-ly/p/5442950.html
题意:
给一个数字N,把数字N分解成连续的K个数字,使得K最大,连续的两个数字必须不相同.栗子 4,可以分成1 2 1,这是满足答案的,不能是 1 1 2 或者 1 1 1 1.
思路:
如果只要求K最大,那么只需要分成N个 1 就好了,但是还有个条件是连续的数字不相同,所以还需要一个数字 2,利用 1 和 2 的组合,使得K最大,1 和 2 可以组成 3,那么如果是 4 那么可以是 1 2 1,如果是 5 那么可以是 2 1 2,即对于数字N,可以分解成 N/3 个 3,余数可能是的0 1 2,如果是0,那么就不用添加,如果是1 再加一个 数字 1,如果是2 再加一个数字 2,就好了.比如 7: 1 2 1 2 1 2 1, 栗如 8: 2 1 2 1 2 1 2.
代码:
#include <bits/stdc++.h>
using namespace std; int main()
{
int n;
while(cin >> n)
{
int ans = ;
if(n % == ) ans = *( n / );
else ans = * (n / ) + ;
cout << ans << endl;
}
return ;
}
CodeForces 669A的更多相关文章
- codeforces 669A A. Little Artem and Presents(水题)
题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- IIS 发布后无法连接数据库(应用池问题)
查找网站对应的 应用池,修改为 .net4.0 然后设置启动32位应用程序为 True
- JavaScript十大经典排序算法
排序算法说明 (1)排序的定义:对一序列对象根据某个关键字进行排序: 输入:n个数:a1,a2,a3,…,an输出:n个数的排列:a1’,a2’,a3’,…,an’,使得a1’ 再讲的形象点就是排排坐 ...
- C++——OOP面向对象理解
从Rob Pike 的 Google+上的一个推看到了一篇叫<Understanding Object Oriented Programming>的文章,我先把这篇文章简述一下,然后再说说 ...
- 【HDU 4300 Clairewd’s message】
Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...
- COGS 930. [河南省队2012] 找第k小的数 主席树
主席树裸板子 #include<cstdio> #include<iostream> #include<algorithm> #define MAXN 100005 ...
- HDU 2639 01背包求第k大
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- UVA 11995 STL 使用
There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...
- typescript的入门
命令行使用tsc 1.安装typescript npm install -g typescript 2.新建一个index.ts 输入export hello class{} 3.编译 tsc ind ...
- jquery实现通用结构折叠面板效果
效果截图: 说明:可以任意添加多个类似结构样式,点击标题栏图片对应隐藏.显示. jquery代码: 思路一:基本方法 <script src="http://apps.bdimg.co ...
- Java并发(10)- 简单聊聊JDK中的七大阻塞队列
引言 JDK中除了上文提到的各种并发容器,还提供了丰富的阻塞队列.阻塞队列统一实现了BlockingQueue接口,BlockingQueue接口在java.util包Queue接口的基础上提供了pu ...