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 ;
}

Segments CodeForces 909B (找规律)的更多相关文章

  1. codeforces 362A找规律

    刚开始以为是搜索白忙活了原来是个简单的找规律,以后要多想啊 此题是两马同时跳 A. Two Semiknights Meet time limit per test 1 second memory l ...

  2. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  3. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  4. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  5. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  6. 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

    题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...

  7. codeforces B. A and B 找规律

    Educational Codeforces Round 78 (Rated for Div. 2) 1278B - 6 B. A and B  time limit per test 1 secon ...

  8. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  9. Codeforces 193E - Fibonacci Number(打表找规律+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...

随机推荐

  1. 浅谈spj

    SPJ(special judge)是个好玩的东西,毕竟各类神奇的题目SPJ经常作为救火工具(比如说一不小心出成验证类的题目). 但SPJ是个坑,毕竟只让用个“testlib.h”,输入还特别奇怪.今 ...

  2. MySQL学习【第七篇索引管理及执行计划】

    一.索引介绍 1.什么是索引? 索引由如字典,目的就是为了更快寻找到要找的内容. 令搜索查询的数据更有目的性,从而提高数据检索的能力 2.索引类型介绍 1.BTREE: B+树索引 2.HASH: H ...

  3. MySQL----MySQL数据库入门----第四章 单表查询

    select [distinct] * | 字段1,字段2,字段3... from 表名 [where 条件表达式] [group by 字段名] [having 条件表示式] [order by 字 ...

  4. 延迟加载图片控件--echo.js

    echo.js的github地址:https://github.com/toddmotto/echo   echo是一个独立的JavaScript.轻量级的.延迟图片加载插件,echo压缩后体积不到1 ...

  5. daterangepicker的个性化使用技巧

    由于该模板不自动将时间戳添加到input中去,始终为NaN,所以,自己选取起始时间与截止时间 var startTime =new Date(new Date().toLocaleDateString ...

  6. 十个常见的Java异常出现原因

    异常是 Java 程序中经常遇到的问题,我想每一个 Java 程序员都讨厌异常,一 个异常就是一个 BUG,就要花很多时间来定位异常问题. 1.NullPointerException 空指针异常,操 ...

  7. MySQL用户账户管理/权限管理/资源限制

    MySQL 的权限表在数据库启动的时候就载入内存,当用户通过身份认证后,就在内存中进行相应权限的存取,这样,此用户就可以在数据库中做权限范围内的各种操作了. mysql 的权限体系大致分为5个层级: ...

  8. 适合初学Altium Designer的教学视频

    以下推荐的我都亲自看过,个人感觉确实不错,可以有助于了解流程,以及一些设计规范 首先是凡亿的PCB教学,贵是贵了点,不过也有免费的,讲解的很详细,而且还有专门的群,610359270 http://w ...

  9. C#基础 base与this关键字

    base和this在C#中被归于访问关键字,顾名思义,就是用于实现继承机制的访问操作来满足对对象成员的访问,从而为多态机制提供更加灵活的处理方式. this是指当前对象本身,而base则是在继承类中访 ...

  10. java入门---运算符&算术运算符&自增自减运算符&关系运算符&位运算符

        计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量.我们可以把运算符分成以下几组: 算术运算符 关系运算符 位运算符 逻辑运算符 赋值运算符 ...