bzoj1263

贪心

n%3==1 分出一个4,其余用3,n%3==2,分出一个2,其余用3,然后高精度就行了

#include<bits/stdc++.h>
using namespace std;
const int N = 5005;
struct BigInt {
    int len;
    int a[N];
    BigInt() { memset(a, 0, sizeof(a)); }
    BigInt friend operator * (const BigInt &a, const int &x) {
        BigInt ret;
        ret.len = a.len;
        for(int i = 1; i <= ret.len; ++i) ret.a[i] = a.a[i] * x;
        for(int i = 1; i <= ret.len; ++i) ret.a[i + 1] += ret.a[i] / 10, ret.a[i] %= 10;
        while(ret.a[ret.len + 1]) 
        {
            ++ret.len;
            ret.a[ret.len + 1] += ret.a[ret.len] / 10;
            ret.a[ret.len] %= 10;
        } 
        return ret;
    }
    void print()
    {
        printf("%d\n", len);
        for(int i = len; i > max(len - 100, 0); --i) printf("%d", a[i]);
        puts("");
    }
} A;
int n;
int main()
{
    scanf("%d", &n);
    A.a[1] = A.len = 1; 
    if(n % 3 == 1) n -= 4, A = A * 4;
    if(n % 3 == 2) n -= 2, A = A * 2;
    for(int i = 1; i <= n / 3; ++i) A = A * 3;
    A.print(); 
    return 0;
}
View Code

 

posted @ 2017-11-02 07:40  19992147  阅读(109)  评论(0编辑  收藏  举报