zoukankan      html  css  js  c++  java
  • Problem B: Ternarian Weights

    大致题意:使用三进制砝码采取相应的措施衡量出给定的数字
    主要思路:三进制,如果 大于 2 向前进位,之前一直没写好放弃了,这次终于写好了……

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <map>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <stack>
    #include <cctype>
    
    const double Pi = atan(1) * 4;
    
    using namespace std;
    long long base[] = {1,1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489,1162261467,3486784401};
    int a[100];
    int tt[110];
    int main()
    {
        //freopen("input.in","r",stdin);
        //freopen("output.in","w",stdout);
        int n;
        cin >> n;
        while(n--){
            int x;
            cin >> x;
            memset(a,0,sizeof(a));
            memset(tt,0,sizeof(tt));
            int tmp = x;
            while(tmp){
                a[++a[0] ] = tmp % 3;
                tmp /= 3;
            }
            for(int i = 1;i <= a[0];i++){
                if(a[i] == 2){
                    a[i+1]++;
                    a[0] = max(i+1,a[0]);
                    tt[ ++tt[0] ] = i;
                    a[i] = 0;
                }
                if(a[i] == 3){
                    a[i+1]++;
                    a[0] = max(i+1,a[0]);
                    a[i] = 0;
                }
            }
            cout << "left pan:";
            for(int i = tt[0];i > 0;i--){
                cout << " " << base[ tt[i] ];
            }
            cout << endl;
            cout << "right pan:";
            for(int i = a[0];i > 0;i--){
                if(!a[i])
                    continue;
                cout << " " << base[i];
            }
            cout  << endl;
            if(n)
                cout << endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Java知识回顾 (8) 集合
    Java知识回顾 (7) 继承、多态与接口、封装
    使用LEANGOO泳道
    使用列表
    LEANGOO用户设置
    创建LEANGOO项目
    为看板添加成员
    创建看板卡片
    创建LEANGOO看板
    创建LEANGOO账号
  • 原文地址:https://www.cnblogs.com/hanbinggan/p/4256447.html
Copyright © 2011-2022 走看看