hdu3029 2010.3.6
来源:互联网 发布:黑龙江网络广播 编辑:程序博客网 时间:2024/05/13 09:58
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"); }}
- hdu3029 2010.3.6
- hdu3029
- hdu2831 2010.3.6
- hdu2832 2010.3.6
- hdu2818 2010.3.6
- hdu2857 2010.3.6
- hdu2881 2010.3.6
- hdu2897 2010.3.6
- hdu3063 2010.3.6
- hdu2458 2010.3.6
- hdu1754 2010.3.6
- hdu1753 2010.3.6
- hdu1041 2010.3.6
- hdu2275 2010.3.6
- hdu2863 2010.3.6
- hdu2850 2010.3.6
- Fiber Network 2010.3.6
- El Dorado 2010.3.6
- eclipse 如何配制项目编译JDK版本
- hdu2275 2010.3.6
- Liferay环境搭建以及与Eclipse的使用
- 网络编程中大小端字节的使用剖析
- 继承
- hdu3029 2010.3.6
- hdu2863 2010.3.6
- 简单探讨可牛影像软件中具有肤质保留功能的磨皮算法及其实现细节
- SVProgressHUD控件使用 进度条
- Subsequence
- 处理错误TypeError: initial_value must be unicode or None, not str
- hdu2850 2010.3.6
- 【BZOJ3290】花神的数论题
- markdown测试