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

 

Input

2

Output

2

Input

3

Output

4

Input

4

Output

6

Sample Output

Hint

As an example, here are the segments and their optimal arrangement into layers for N = 4.

 

题解:给你长度为n的线段,有n*(1+n)/2个子线段,将他们压缩,使压缩后线段最少,就是找规律,之前做过一次,昨天做的时候忘了,又现推的,分奇偶讨论,偶数为偶数递增,奇数为奇数递增。

代码如下:

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 10007
#define N 107
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define mod 1000000007
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    if(n%2==0)
    {
        int sum=0;
        for(int i=2;i<=n;i+=2)
            sum+=i;
        cout<<sum<<endl;
    }
    else
    {
        int sum=0;
        for(int i=1;i<=n;i+=2)
            sum+=i;
        cout<<sum<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值