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. JavaScript变量类型检测总结

    JavaScript中的变量类型: 基本类型值:Undefined,Null,Boolean,Number和String. 按值访问(可直接操作保存在变量中的变量值): 复制规则:当复制基本类型值时: ...

  2. jQuery属性操作之.val()函数

    目录 .val()实例方法的三种用法 .val()函数源码 调用形式:$('xxx').val(); 调用形式:$('xxx').val(value); 调用形式:$('xxx').val(funct ...

  3. PL/SQL 报错:动态执行表不可访问,本会话的自动统计被禁止。 在执行菜单里你可以禁止统计,或在v$session,v$sesstat 和vSstatname表里获得选择权限。

    现象: 第一次用PL/SQL Developer连接数据库,若用sys用户登录并操作则正常,若用普通用户比如haishu登录并创建一个表则报错“动态执行表不可访问,本会话的自动统计被禁止.在执行菜单里 ...

  4. 如何在HHDI中调用Java文件

    创建执行JS语句任务,在脚本中输入相关代码,两种写法: ------------------------写法一 // 直接调用类的路径 var now = com.haohe.utils.DateUt ...

  5. Python学习手册之Python介绍、基本语法(一)

    一.什么是python? python是一种高级的编程语言.它适合编写一些应用程序,比如:网站编程,脚本编程,科学计算和最近非常热门的AI(人工智能).目前,Google,腾讯,百度,阿里巴巴,豆瓣都 ...

  6. (数据科学学习手札52)pandas中的ExcelWriter和ExcelFile

    一.简介 pandas中的ExcelFile()和ExcelWriter(),是pandas中对excel表格文件进行读写相关操作非常方便快捷的类,尤其是在对含有多个sheet的excel文件进行操控 ...

  7. The Road to learn React书籍学习笔记(第二章)

    The Road to learn React书籍学习笔记(第二章) 组件的内部状态 组件的内部状态也称为局部状态,允许保存.修改和删除在组件内部的属性,使用ES6类组件可以在构造函数中初始化组件的状 ...

  8. 20155206 《Java程序设计》实验三实验报告

    20155206 <Java程序设计>实验三实验报告 实验内容 Java敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 提交一: 提交二: 提交三: 提交四:

  9. 20155322 2016-2017-2 《Java程序设计》第10周学习总结

    20155322 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 第10周学习的主要内容Java和Android开发学习指南(第二版)(EPUBIT,Jav ...

  10. 对Linux命令od -tc -tx1的C语言程序实现myod-优化版

    导语 自编od C语言实现版名为myod 上个星期有一个初代版,链接- myod原版 这星期的课上要求实现myod-系统调用版本,要求如下 1 参考教材第十章内容 2 用Linux IO相关系统调用编 ...