hdu3029 2010.3.6

hdu3029 2010.3.6

将题目转化成了三进制,如果数学学得不好的话,那就多写几组数据找规律,总结出来处理方法

 

Scales 3029

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 95    Accepted Submission(s): 45

 

 

Problem Description

Give you a scale, a goods weigts mkilograms. And then give you some stones weighting 1, 3, 9, 27, ..., 3^k. Ofcourse, the number of different weights' is only ONE.

 

Now put the goods on the left of scale. Andthen you should put some stones on two sides of scale to make the scalebalanced.

 

 

Input

An integer m, stands for the weights of thegoods (0 ≤ m ≤ 100 000 000)

 

 

Output

You should output two lines.

 

In the first line, the first integer N1 isthe number of stones putting on the left of scale, and then N1 integersfollow(in the ascend order), indicating the weight of stones putting on theleft, seperated by one space. In the second line, please use the same way asthe first line's to output the N2, which is the number of stones putting on theright side. Then following N2 integers, which are in ascending order, indicatethe stones' weight putting on the right side.

 

 

Sample Input

42

30

 

 

Sample Output

3 3 9 27

1 81

0

2 3 27

 

 

Source

2009 Multi-University Training Contest 6 -Host by WHU

 

 

Recommend

gaojie


#include <stdio.h>
#include <string.h>

int num[50],mid[50],m,lnum,left[50],right[50];
int ans1[50],ans2[50],lans1,lans2;
__int64 ans[20]={0,1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489};

void change()
{
    int mm=m,i;
    while (mm)
    {
        lnum++;
        num[lnum]=mm%3;
        mm/=3;
    }
    memcpy(mid,num,sizeof(num));
}

void main()
{
    int i;
    while(scanf("%d",&m)!=EOF)
    {
        lnum=0;
        memset(left,0,sizeof(left));
        memset(right,0,sizeof(right));
        memset(num,0,sizeof(num));
        change();
        for(i=1;i<=lnum;i++)
            if (num[i]==2)
            {
                left[i]=1;
                num[i+1]++;
            }
            else
                if (num[i]>2)
                    num[i+1]++;
        lnum++;
        for(i=1;i<=lnum;i++)
        {
            right[i]+=left[i]+mid[i];
            right[i+1]+=right[i]/3;
            right[i]%=3;
        }
        lnum++;
        lans1=0;
        lans2=0;
        for(i=1;i<=lnum;i++)
            if (left[i]==1)
            {
                lans1++;
                ans1[lans1]=i;
            }
        for(i=1;i<=lnum;i++)
            if(right[i]==1)
            {
                lans2++;
                ans2[lans2]=i;
            }
        printf("%d",lans1);
        for(i=1;i<=lans1;i++)
            printf(" %d",ans[ans1[i]]);
        printf("\n");
        printf("%d",lans2);
        for(i=1;i<=lans2;i++)
            printf(" %d",ans[ans2[i]]);
        printf("\n");
        
        
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值