牛客网--15973--水题

题目描述:
一张地图上有有N个城市,他们可以通过双向道路互相连接,但是每两座城市只能有一条双向道路互相连接。

现在我们想要满足条件“地图中不能有任意三个城市可以互相直达”,请问满足这个条件的最大道路数是多少?
输入描述:
多组输入
每组输入一个N(1<=N<=1000)
输出描述:
每组答案输出一行
输入:
4
2
3
输出:
4
1
2
题意:
题目描述
题解
画个图推一下
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn = 1000 + 5;
int f[maxn];

void init(){
    f[1] = 0;
    f[2] = 1;
    f[3] = 2;
    f[4] = 4;
    for(int i = 5; i <= maxn; i ++){
        f[i] = f[i - 1] + i / 2;
    }
}

int main(){
    int n;
    init();
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",f[n]);
    }
    return 0;
}

发布了228 篇原创文章 · 获赞 1 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/Ypopstar/article/details/105175803