• HDU2047 阿牛的EOF牛肉串


    题目:https://blog.csdn.net/qq_40932661?t=1

    表面上看去似乎无从下手。但是可以从前面地推出后面的

    递推:

    假如涂第N个位置,有两种可能,①涂O ②不涂O。

    如果涂O的话,前面不能是O,只能是E或F两种, 即2*f(n-2)

    不涂O的话,N位置可以放E或F两种即2*f(n-1)

    所以 f[n] = 2*(f[n-1] + f[n-2])

    !!!输入挂是一个坑点。刚入门。才知道while(scan_d(n))   不能是while((~scan_d)),  否则OLE

    AC代码:

    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <stdlib.h>
    #include <string>
    #include <bitset>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <algorithm>
    #include <sstream>
    #include <stack>
    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(),(x).end()
    #define fi first
    #define se second
    #define SZ(x) ((int)(x).size())
    #define FO freopen("in.txt", "r", stdin);
    #define lowbit(x) (x&-x)
    typedef vector<int> VI;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> PII;
    const ll mod=1000000007;
    const int inf = 0x3f3f3f3f;
    ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    template <class T>
    inline bool scan_d(T &ret)
    {
        char c; int sgn;
        if (c = getchar(), c == EOF) return 0; //EOF
        while (c != '-' && (c < '0' || c > '9')) c = getchar();
        sgn = (c == '-') ? -1 : 1;
        ret = (c == '-') ? 0 : (c - '0');
        while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
        ret *= sgn;
        return 1;
    }
    inline void out(ll x)
    {
        if (x > 9) out(x / 10);
        putchar(x % 10 + '0');
    }
    
    long long f[50];
    int main() {
    	f[1] = 3;
    	f[2] = 8;
    	rep(i, 3, 45) {
    		f[i] = 2*(f[i-1] +f[i-2]);
    	}
    	int n;
    	while(scan_d(n)) {
    		out(f[n]);
    		printf("
    ");
    	}
    } 
    
    
    
  • 相关阅读:
    二叉搜索树的第k个结点
    序列化二叉树
    把二叉树打印成多行
    按之字形顺序打印二叉树
    对称的二叉树
    二叉树的下一个结点
    删除链表中重复的结点
    链表中环的入口结点
    字符流中第一个不重复的字符
    基数排序的理解和实现(Java)
  • 原文地址:https://www.cnblogs.com/ACMerszl/p/9572952.html
Copyright © 2020-2023  润新知