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;
}

时间: 2024-10-24 06:38:49

Problem B: Ternarian Weights的相关文章

Problem F Free Weights

二分答案. 思路:对于二分给定的mid,即当前允许移动的最大重量,我们可以把小于改重量的标记一下,然后把没有标记的按照顺序放到另一个数组,然后判断是否满足两两相同. #include<bits/stdc++.h> using namespace std; const int N=1E6+7; int arr[N]; int brr[N]; int crr[N]; bool mark[N],mark1[N]; const int INF=1e9+7; const int mm=1e9; int

Deep Learning in a Nutshell: History and Training

Deep Learning in a Nutshell: History and Training This series of blog posts aims to provide an intuitive and gentle introduction to deep learning that does not rely heavily on math or theoretical constructs. The first part in this series provided an

Regularization from Large Wights Perspective

Problem with Large Weights Large weights in a neural network are a sign of overfitting. A network with large weights has very likely learned the statistical noise in the training data. This results in a model that is unstable, and very sensitive to c

Problem with blending edges of connected shapes

提供展示代码: agg::rendering_buffer &rbuf = rbuf_window();      agg::pixfmt_bgr24 pixf(rbuf); typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;      renderer_base_type renb(pixf); typedef agg::renderer_scanline_aa_solid<renderer_bas

General Problem Solving Techniques [Intermediate-1]~F - Tian Ji -- The Horse Racing

Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others. Both of Tian and the king have three horses in different classes,

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

[论文]A Link-Based Approach to the Cluster Ensemble Problem

论文作者:Natthakan Iam-On, Tossapon Boongoen, Simon Garrett, and Chris Price 下次还是在汇报前先写了论文总结,不然有些点汇报时容易忘了说,以前看的论文看补不补上来吧,有时间再说. 前言: 这篇论文是关于聚类集成的,成熟的聚类集成框架是将多个聚类算法的结果汇聚在一起,然后使用一致性函数得出最终的聚类结果,论文中认为这两步中间的操作属于原数据上的操作,比较粗糙,所以提出了一种算法,对汇总后聚类结果进行进一步处理,然后再使用一致性函数

cs224d problem set2 (三) 用RNNLM模型实现Language Model,来预测下一个单词的出现

今天将的还是cs224d 的problem set2 的第三部分习题, 原来国外大学的系统难度真的如此之大,相比之下还是默默地再天朝继续搬砖吧 (注意前方高能,一大批天书即将来袭) ''' Created on 2017年9月26日 @author: weizhen ''' import getpass import sys import time import numpy as np from copy import deepcopy from utils import calculate_p

分析公式 Codeforces 528B Clique Problem

http://codeforces.com/contest/528/problem/b Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some