FOJ有奖月赛-2015年11月 Problem A 据说题目很水

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2205

题        意:给你 n个点,任意两个点由不超过一条边直接相连,而且没有点的边连向自身且不能有任意三个点能够相互连通,而且所有的边数目最多,

思        路:找规律

当n = 1, ans = 0; n = 2, ans = 1; n = 3, ans = 2; n = 4, ans = 4;n = 5, ans = 6;.....
可见:
a[2]-a[1] = 1;
a[3]-a[2] = 1;
a[4]-a[3] = 2;
a[5]-a[4] = 2;
a[6]-a[5] = 3;
a[7]-a[6] = 3;
。          。
。          。
。          。
显而易见.
代码如下:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef __int64 LL;

int ans[1003];

int main()
{
    int T;
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 1;
    ans[3] = 2;
    ans[4] = 4;
    for( int i = 5; i < 1002; i ++ )
    {
        ans[i] = ans[i-1] + ans[i-2];
        cout<<i<<" "<<ans[i]<<endl;
    }
    scanf ( "%d", &T );
    while( T-- )
    {
        int n;
        scanf( "%d", &n );
        printf( "%d\n", ans[n] );
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值