2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D

Problem D. Distribution in Metagonia Input file: distribution.in Output file: distribution.out Time limit: 2 seconds Memory limit: 256 megabytes There are one hundred noble families in the country of Metagonia, and each year some of these families receive several ritual cubes from the Seer of the One. The One has several rules about cube distribution: if a family receives at least one cube, every prime divisor of the number of cubes received should be either 2 or 3, moreover if one family receives a > 0 cubes and another family in the same year receives b > 0 cubes then a should not be divisible by b and vice versa. You are the Seer of the One. You know in advance how many cubes would be available for distribution for the next t years. You want to find any valid distribution of cubes for each of these years. Each year you have to distribute all cubes available for that year.

Input The first line of input file contains a single integer t — the number of years to come (1 ≤ t ≤ 1000). Each of the following t lines contains a single integer ni — the number of cubes to distribute in i-th year (1 ≤ ni ≤ 1018).

Output For each year i output two lines. The first line should contain mi — the number of families that would receive at least one cube in i-th year (1 ≤ mi ≤ 100). The second line should contain mi integers — the number of cubes received by each family. The sum of these numbers should be equal to ni .

Example

distribution.in

distribution.out

input:

4

1

2

3

10

output:

1

1

1

2

1 3

2

4 6

题意:  输入一个数n,把n拆分成多个数的和,且每个数的素因子只有2和3,数之间不能整除;

思路:  将n整除以2^t,使n变为奇数,找到3^k<=n,最大的k,则2^t*3^k为拆分后的一个数,则n-2^t*3^k必为一个偶数,再做相同的操作得到下一个拆分的数,直至n=0;

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL; vector <LL> vec;
int main()
{
//freopen("distribution.in","r",stdin);
//freopen("distribution.out","w",stdout);
int T;
LL n;
cin>>T;
for(int i=; i<T; i++)
{
vec.clear();
cin>>n;
for(int i=; ; i++)
{
if(n <= )
break;
LL tp = n, sum = ;
while(tp)
{
if(tp & )
break;
tp /= ;
sum *= ;
} while(sum <= n)
sum *= ;
sum /= ;
vec.push_back(sum);
n -= sum;
}
cout<<vec.size()<<endl;
for(int i=; i<vec.size(); i++)
cout<<vec[i]<<" ";
cout<<endl;
}
return ;
}

【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 模拟赛小结:2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest

    2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest 2019年10月11日 15:35-20:35(Solved 8,Penalty 675 ...

  4. 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest (9/12)

    $$2015-2016\ ACM-ICPC,\ NEERC,\ Northern\ Subregional\ Contest$$ \(A.Alex\ Origami\ Squares\) 签到 //# ...

  5. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  6. 2016 NEERC, Northern Subregional Contest G.Gangsters in Central City(LCA)

    G.Gangsters in Central City 题意:一棵树,节点1为根,是水源.水顺着边流至叶子.该树的每个叶子上有房子.有q个询问,一种为房子u被强盗入侵,另一种为强盗撤离房子u.对于每个 ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  8. 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem F. Format

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:1s 空间限制:512MB 题目大意: 给定一个字符串,使用%[...] ...

  9. 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest Problem I. Integral Polygons

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个凸多边形,有一种连接两个 ...

随机推荐

  1. 知方可补不足~sqlserver中使用ROW_NUMBER进行的快速分页

    回到目录 这个在SQL2005之后最见的一种分页方式,也是Linq默认生成的执行分页的方法(skip,take),当然在性能上小数量没有问题,在数据达到百万时会很慢,这是我们要清楚的,有时我们在LIN ...

  2. rewrite规则写法及nginx配置location总结

    rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用. 例如http://seanlook.com/a/we/index.php ...

  3. 查看 table,view,sp的定义

    1, 查看用户创建的Proc,View, UDF,trigger 的定义 sys.sql_modules Returns a row for each object that is an SQL la ...

  4. mysqldump导出不包含存储过程

    mysqldump导出不包含存储过程 mysqldump -u 数据库用户名 -p -n -t -d -R --triggers=false 数据库名 > 文件名 这样单独把存储过程和函数导出 ...

  5. Android开发之网络

    很多初学Android开发的人员对网络这一点感觉很高大上,现在我就和大家分享一下我的学习心得. 就目前的Android手机来说,可能存在5种网络状态: ----无网络(这种状态可能是因为手机停机,网络 ...

  6. RAC Concept

    1. RAC的高可用性 RAC的高可用性主要包含以下几点: 1> 实现节点间的负载均衡. 2> 实现失败切换的功能. 3> 通过Service组件来控制客户端的访问路径. 4> ...

  7. Project简介

    Microsoft Project (Project)是一个国际上享有盛誉的通用的项目管理工具软件,凝集了许多成熟的项目管理现代理论和方法,可以帮助项目管理者实现时间.资源.成本的计划.控制,协助项目 ...

  8. Testing - 测试基础 - 阶段

    估算 测试对软件工作量的估算的准确性 测试评估软件系统的状况的准确性 关注点: 不准确的估算 不适当的开发过程 不真实的状态报告 如何知道对工作量的估算是正确的 估算工作量的工具很容易出错 对软件工作 ...

  9. js cookie存储方法

    /*! * jQuery Cookie Plugin v1.4.0 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Kla ...

  10. J2EE修炼之四书五经[转自2004年程序员]

    J2EE修炼之四书五经 作者:彭晨阳 J2EE其实没有四书五经,因为J2EE一直如汹涌澎湃的大江,推陈出新,不断高速发展,这是一种带领我们走向未来的技术.当然,如何在这种气势如虹的潮流之中不至于迷失方 ...