链接: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的更多相关文章

  1. codeforces 669A A. Little Artem and Presents(水题)

    题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. Socket常见错误代码与描述

    最近程序 出现 几次 Socket 错误, 为了便于 差错.. 搜了一些 贴在这里.. 出现网络联机错误Socket error #11001表示您的计算机无法连上服务器,请检查您的Proxy设定以及 ...

  2. Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记

    夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...

  3. [Leetcode] search a 2d matrix 搜索二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  4. 遇到问题---java---myeclipse发布项目打包项目resource资源有缓存---log4j.properties新配置不起作用

    在使用myeclipse过程中遇到一个很奇怪的问题,无论是在myeclipse中deploy发布到tomcat或者打包打成war后在tomcat中运行解压,resource都有缓存的感觉. 比较明显的 ...

  5. wya费用流

    #include<bits/stdc++.h> using namespace std; #define M 1005 #define inf 0x7fffffff #define T 6 ...

  6. Tile Cut~网络流入门题

    Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...

  7. sql 批量更新表中多字段为不同的值

    ,),,),rand()) select newid() ,) update tablename , FB,)) , ), FC,)) , )

  8. bzoj 1880 最短路

    我们首先知道,答案肯定是最短路图中的某段公共链,那么设(x,y)为x到y的最短路,那么答案为((s1,t1)+(s2,t2)-min((s1,s2)+(t1,t2),(s1,t2),(s2,t1))) ...

  9. kvm的vmcall

    这几个接口的区别在于参数个数的不用,本质是一样的.挑个参数最多的看下: static inline long kvm_hypercall4(unsigned int nr, unsigned long ...

  10. 转一篇CF题目的博客

    题意: 给你一颗n(n<=10^5)个节点树根为1的树,然后进行dfs,求每个点,在dfs中被访问时间的期望. let starting_time be an array of length n ...