[Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)
来源:互联网 发布:js仿微信拆红包源码 编辑:程序博客网 时间:2024/06/05 17:44
Codeforces - Gym10081D (NEERC)
给定一个数,将其变成若干个数的和
如果这些数有因子,那么只能是 2或 3
并且这些数两两不能除尽
构造题
如果这个数为 1,那么答案就为 1
若不为 1,那么如果他是奇数
那么我减去最大的一个 3次幂转化为一个偶数,
再不断地提出 2,变成一个奇数,循环直到其变为 1
所以这个数
其中 3的次数
而展开后 2的次数
所以这些数按顺序排开,他们 3这个因子的次数是递减的
而 2这个因子的次数是递增的,所以相互不能整除,即为答案
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <cctype>#include <map>#include <set>#include <queue>#include <bitset>#include <string>#include <complex>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define SQR(a) ((a)*(a))#define PCUT puts("\n----------")int siz;LL outp[110], pow3[110];int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif #ifndef LOCAL freopen("distribution.in", "r", stdin); freopen("distribution.out", "w", stdout); #endif pow3[0]=1; for(int i=1; i<=39; i++) pow3[i]=pow3[i-1]*3; int T; scanf("%d", &T); for(int ck=1; ck<=T; ck++) { LL N, mul=1; siz = 0; cin >> N; while(N) { while(!(N&1)) {mul<<=1; N>>=1;} for(int i=39; i>=0; i--) if(pow3[i]<=N) { outp[siz++] = mul*pow3[i]; N -= pow3[i]; break; } } printf("%d\n", siz); for(int i=0; i<siz; i++) cout << outp[i] << ' '; puts(""); } return 0;}
0 0
- [Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)
- 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D:Distribution in Metagonia(构造)
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】【脑洞 构造】Distribution in Metagonia 把数以2^p3^
- 2015-2016ACM-ICPC NEER northern-subregional-contest D Distribution in Metagonia 模拟构造
- GYM 100801D Distribution in Metagonia【思维】
- [Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)
- Codeforces 798D Mike and distribution 构造
- [可图性判定 Havel-Hakimi定理 构造] Codeforces Gym 100269 NEERC 13 Northern K. Kids in a Friendly Class
- 数的拆分(数的划分)
- [构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
- [构造] Codeforces Gym 100553 NEERC 14 E. Epic Win!
- Codeforces 798D Mike and distribution (构造 + 脑洞 推荐)
- 数的拆分
- 数的拆分
- 数的平方和拆分
- 10.21【Codeforces NEERC 胡玩记】
- fjnu 1978 数的拆分
- 逆序数的拆分计算
- 输入一个递增排序的数组和一个数字sum,在数组中查找两个数,使得他们的和正好是sum
- 创业公司实习感受以及规划
- apue 第5章 标准I/O库
- php unset销毁变量,释放内存
- Android通知Notification的功能与用法
- [Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)
- String.split()方法介绍
- 第二周项目3 体验复杂度(汉诺塔)
- C++ 顺序容器注意点
- 《effective C++》读书笔记(三)
- 关于const
- 15年资深架构师总结的经验
- 用递归算法求解汉诺塔问题
- Js 对象中使用[] 和 . 的区别