2013ICPC长春 HDU 4814 Golden Radio Base 乱搞

来源:互联网 发布:音效软件 知乎 编辑:程序博客网 时间:2024/06/05 09:09

题意:给十进制数转换为黄金分割进制,要求每位为0或1,且不能出现相邻的1


题解:令x为黄金分割比,1 = x^(-1) + x^(-2),  n = n*(x^(-1) + x^(-2)), 题目提示了两种操作 x^1 + 1 = x^2, 2*x^2 = x^3 + 1, 最多100位数所以每次扫一遍乱搞一下就可以了,操作一可以减少总的数字的数量所以优先做1操作可以减少次数



#include <iostream>#include <cstdio>#include <cctype>#include <algorithm>#include <cstring>#include <string>#include <cmath>#include <vector>#include <set>#include <stack>#include <sstream>#include <queue>#include <map>#include <functional>#include <bitset>#include <ctime>using namespace std;#define pb push_back#define mk make_pair#define ll long long#define ull unsigned long long#define pii pair<int, int>#define mk make_pair#define fi first#define se second#define ALL(A) A.begin(), A.end()#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)#define repr(i, n) for(int (i)=(int)(n);(i)>=0;(i)--)#define repab(i,a,b) for(int (i)=(int)(a);(i)<=(int)(b);(i)++)#define reprab(i,a,b) for(int (i)=(int)(a);(i)>=(int)(b);(i)--)#define sc(x) scanf("%d", &x)#define pr(x) printf("x:%d\n", x)#define fastio ios::sync_with_stdio(0), cin.tie(0)#define frein freopen("in.txt", "r", stdin)#define freout freopen("out.txt", "w", stdout)#define freout1 freopen("out1.txt", "w", stdout)#define lb puts("")#define lson ((rt<<1)+1)#define rson ((rt<<1)+2)#define mid ((l+r)/2)#define lmid (l+(r-l)/3)#define rmid (r-(r-l)/3)#define debug cout<<"???"<<endlconst double PI = 3.1415926535897932384626433;const ll mod = 2147493647;const int INF = 0x3f3f3f3f;const double eps = 1e-12;template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}const int maxn = 200, base = 100;int cnt[maxn], n;void print(int l, int r){    for(int i = r; i >= l; i--){        printf("cnt[%d]:%d\n",i,cnt[i]);    }lb;}int main(){    //frein;    //freout;while(scanf("%d", &n) != EOF){        //cout << n << endl;        memset(cnt, 0, sizeof(cnt));        cnt[base-1] = cnt[base-2] = n;        int flg = 1;        while(1){            flg = 0;            for(int i = 0; i < maxn-1; i++){                while((cnt[i] && cnt[i+1])||cnt[i] >= 2){                    //print(27,33);                    flg = 1;                    if(cnt[i] && cnt[i+1]){                        int t = min(cnt[i], cnt[i+1]);                        cnt[i+2] += t;                        cnt[i] -= t;                        cnt[i+1] -= t;                    }                    if(cnt[i] >= 2){                        int t = cnt[i]/2;                        cnt[i] -= 2*t;                        cnt[i+1] += t;                        cnt[i-2] += t;                    }                }            }            if(flg == 0) break;        }        int len = 0, l = 500, r = base;        for(int i = 0; i < maxn; i++){            if(cnt[i]) l = min(l,i), r = max(r,i);        }        for(int i = r; i >= l; i--){            printf("%d",cnt[i]);            if(i == base && i > l) printf(".");        }lb;    }return 0;}


原创粉丝点击