Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
2016-11-10 20:10
169 查看
原题传送门
题意
简要翻译
题解
坑和手抖和蒟蒻的故事
代码
S={1,3,9,27,81,...}
Consider the sequence of all subsets of S ordered by the value of the sum of their elements. The question is simple: find the set at the n-th position in the sequence and print it in increasing order of its elements.
{ }
{ 1 }
{ 3 }
{ 1, 3 }
{ 9 }
{ 1, 9 }
{ 3, 9 }
{ 1, 3, 9 }
{ 27 }
{ 1, 27 }
{ 3, 27 }
{ 1, 3, 27 }
好像有点意思了,,
重点观察5项,9项,3项。。。。
然后尽情的YY吧
发现了点啥?
对于每一项 x ,将x−1进行二进制分解,即当x=9时,将x−1分解成{1,0,0},输出27,也就是说,如果x−1中包含2n,就在结果中输出3n,玄学规律,,,,
由于这道题目我是使用了2进制来判断,,在遇到超过long long范围的数据会崩掉,,,(mod一下网上的大神们,他们都用了long long然而却没出任何问题= =)
题意
简要翻译
题解
坑和手抖和蒟蒻的故事
代码
原题传送门
题意:
Consider the set of all non-negative integer powers of 3.S={1,3,9,27,81,...}
Consider the sequence of all subsets of S ordered by the value of the sum of their elements. The question is simple: find the set at the n-th position in the sequence and print it in increasing order of its elements.
简要翻译:
对于一个由3n组成的序列,考虑它的所有子集,以该子集中所有数的和作为这个子集的权值,题目要求求出第nth个子集,并将其中元素从小到大输出题解:
首先这是一道数学题对吧,,先手动模拟出几项来找找规律:{ }
{ 1 }
{ 3 }
{ 1, 3 }
{ 9 }
{ 1, 9 }
{ 3, 9 }
{ 1, 3, 9 }
{ 27 }
{ 1, 27 }
{ 3, 27 }
{ 1, 3, 27 }
好像有点意思了,,
重点观察5项,9项,3项。。。。
然后尽情的YY吧
发现了点啥?
对于每一项 x ,将x−1进行二进制分解,即当x=9时,将x−1分解成{1,0,0},输出27,也就是说,如果x−1中包含2n,就在结果中输出3n,玄学规律,,,,
坑和手抖和蒟蒻的故事:
高精度乘法进位条件写成了n>10=。=由于这道题目我是使用了2进制来判断,,在遇到超过long long范围的数据会崩掉,,,(mod一下网上的大神们,他们都用了long long然而却没出任何问题= =)
代码:
#include <cstdio> #include <cstring> #include <algorithm> //#define debug struct bigint{ int num; int a[1000]; void print(void) { for (int i = num; i >= 1; i--) { printf("%d", a[i]); } } }; bigint pow3[100]; long long pow2[100]; int n; unsigned long long x; bigint operator * (bigint xx, int p) { for (int i = 1; i <= xx.num; i++) { xx.a[i] *= p; } for (int i = 1; i <= xx.num; i++) { if (xx.a[i] >= 10) { xx.a[i+1] += xx.a[i] / 10; xx.a[i] %= 10; } } if (xx.a[xx.num+1] == 0) return xx; xx.num++; while (xx.a[xx.num] >= 10) { xx.a[xx.num+1] += xx.a[xx.num] / 10; xx.a[xx.num] %= 10; xx.num++; } return (xx); } int main () { freopen("1.txt", "w", stdout); pow2[0] = 1; pow3[0].num = 1; pow3[0].a[1] = 1; for (int i = 1; i <= 62; i++) { pow2[i] = pow2[i-1] * 2; pow3[i] = pow3[i-1] * 3; } #ifdef debug for (int i = 1; i <= 62; i++) { pow3[i].print(); printf("\n"); } #endif while(scanf("%llu", &x) == 1 && x) { x--; bool pflag = 0; printf("{"); //if (x == 0) printf(" "); for (int i = 0; i <= 62; i++) { if ((x & pow2[i]) == pow2[i]) { if (pflag) printf(","); printf(" "); pow3[i].print(); pflag = 1; } } printf(" }\n"); } return 0; }
相关文章推荐
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- POJ 1906 Three Powers
- (Relax 数论1.19)POJ 3244 Difference between Triplets(找规律..//公式max(a,b,c)-min(a,b,c)=(|a-b|+|b-c|+|a-c)
- POJ 2800 Joseph’s Problem 数论找规律
- POJ2407 ZOJ1906 UVA10229 Relatives【欧拉函数+数论】
- (Relax 数论 1.18)POJ 3372 Candy Distribution(找规律,判断一个数看其是否是2的多少次幂)
- <模板>(Miller-Rabin和Pollard_rho算法)poj 2429 GCD & LCM Inverse (数论)