Segments CodeForces 909B (找规律)
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
2
2
3
4
4
6
Hint
As an example, here are the segments and their optimal arrangement(最优排列) into layers for N = 4.

#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 (找规律)的更多相关文章
- codeforces 362A找规律
刚开始以为是搜索白忙活了原来是个简单的找规律,以后要多想啊 此题是两马同时跳 A. Two Semiknights Meet time limit per test 1 second memory l ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
- 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 ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces 193E - Fibonacci Number(打表找规律+乱搞)
Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...
随机推荐
- 免费申请 WebStorm 使用许可 - free JetBrains Open Source license(s)
闲聊 步入前端切图仔行列的我曾多次纠结过「到底使用哪种编辑器写前端好用?」这样的问题,前前后后尝试过 Dreamweaver .HBuilder .Sublime Text .Atom 和现在主要使用 ...
- Linux基础-1.Linux命令及获取帮助
1.Linux命令的格式 1)了解Linux命令的语法格式: 命令 [选项] [参数] 2)掌握命令格式中命令.选项.参数的具体的含义 a)命令:告诉Linux(UNIX)操作系统做(执行)什么 b) ...
- ionic ios 打包发布流程
1.ionic cordova resources ios 在windows下 生成ios资源包 2.拷贝ionic 项目到mac电脑 不用拷贝platforms 并解压 3.正常情况下wido ...
- Angularjs中的超时处理
关键代码: // 定义一个定时器, 设置5s为请求超时时间 var timer = $timeout(function () { console.log('登录超时!'); // 模拟提示信息 },5 ...
- redis必会
1.NosqL 非关系型数据库,里面包含Redis和MondoDB2.为什么会用到关系型数据库?因为当数据量太多,访问人数过多的时候,在访问关系型数据库时会到硬盘里进行读写过多 这样就会导致访问速度很 ...
- 大二作业——操作系统实验——C语言用双向链表,模拟实现动态分区式存储管理
实验:动态分区式存储管理 实验内容: 编写程序模拟完成动态分区存储管理方式的内存分配和回收.实验具体包括:首先确定内存空闲分配表:然后采用最佳适应算法完成内存空间的分配和回收:最后编写主函数对所做工作 ...
- 准确率(accuracy),精确率(Precision),召回率(Recall)和综合评价指标(F1-Measure )----转
原文:http://blog.csdn.net/t710smgtwoshima/article/details/8215037 Recall(召回率);Precision(准确率);F1-Meat ...
- imshow()不显示灰度图像
在matlab中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算.在matlab中,为了保证精度,经过了运算的图像矩阵I其数据类型会从unit8型变成double型.如果 ...
- 证明SG中梯度的期望等于GD的梯度
参考链接: https://zhuanlan.zhihu.com/p/36435504
- Postgresql HStore 插件试用小结
一, 安装 环境介绍:官方说postgresql 9.3 版本之后支持HStore 插件,目前最新版本10.3 本次测试版本:10.1 或 9.6.2 进入psql 运行环境,使用管理员(高级 ...