Description

You are given an integer N. Consider all possible segments (线段,划分)on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be  of them.

You want to draw these segments in several layers so that in each layer the segments don't overlap(重叠) (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.

Find the minimal number of layers(层次) you have to use for the given N.

Input

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output

Output a single integer - the minimal number of layers required to draw the segments for the given N.

Sample Input

Input
2
Output
2
Input
3
Output
4
Input
4
Output
6

Hint

As an example, here are the segments and their optimal arrangement(最优排列) into layers for N = 4.

 
题目意思;给你一条n长的线段,我们可以将其划分为n*(n+1)/2个子线段。现在要求子线段在坐标轴上的位置不动,将所有的子串进行压缩,不能出现重叠,问最少能够得到几层原n长的线段。
解题思路:当时是我队友搞的这道题,我一向对找规律的题目很头疼,他就是一一枚举发现的规律。
 #include <stdio.h>
using namespace std;
int main()
{
int n,k,i,a[];
a[]=;
a[]=;
a[]=;
for(i=;i<=;i++)
{
k=i*(i+)/;///总的子线段数
a[i]=k-a[i-];
}
while(~scanf("%d",&n))
{
printf("%d\n",a[n]);
}
return ;
}

但其实也可以这样想,最后得到的层次数是原来长度为n的线段的若干条可能还会有部分,又因为每一层的线段都是子串在坐标轴上不动拼接得来的,那么我们将线段分成一个个的坐标上的点,那么出现次数最多的那个点的次数就是层次数!!!

 #include<stdio.h>
#include<algorithm>
using namespace std;
int vis[];
int main()
{
int n,j,i,k,ans;
ans=;
scanf("%d",&n);
for(i=; i<=n; i++)
{
for(j=i; j<=n; j++)///划分子段
{
for(k=i; k<=j; k++)///将子段拆成一个个的点
{
vis[k]++;
}
}
}
for(i=; i<=; i++)
{
ans=max(ans,vis[i]);
}
printf("%d\n",ans);
return ;
}

最新文章

  1. ViewPager +Fragment 滑动游标
  2. 抄书 Copying Books UVa 714
  3. java 构造方法
  4. Android的构造器
  5. cuffdiff 和 edgeR 对差异表达基因的描述
  6. 【转】Php+ajax+jsonp解决ajax跨域问题
  7. c# 事件为何要继承EventArgs
  8. C#实现发送邮件——核心部分代码
  9. C++中的快速排序(使用vector和数组的不同)
  10. UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)
  11. sql基本语法:
  12. C#的装箱和拆箱
  13. 无锁队列--基于linuxkfifo实现
  14. Linux监控工具vmstat命令详解
  15. 载入DLL中的图片资源生成Skia中的SkBitmap对象
  16. 模拟Vue之数据驱动
  17. Dynamic Web Module 3.0 requires Java 1.6 or newer.的解决
  18. SpringMVC源码分析--容器初始化(三)HttpServletBean
  19. Space Invaders 太空侵略者
  20. nfs环境搭建报错clnt_create: RPC: Program not registered

热门文章

  1. py基础---多线程、多进程、协程
  2. pycharm使用杂记
  3. Java使用JodaTime处理时间
  4. Pyhton-类(2)
  5. 批处理之 for /f 中的delims和tokens
  6. Java NIO (1)
  7. ASP.NET Core 资源打包与压缩
  8. Django模型中的元选项和object对象
  9. OpenFlow1.3.3 学习记录(持续更新)
  10. 20155224聂小益 2016-2017-2 《Java程序设计》第1周学习总结