Continuous Login


Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge

Pierre is recently obsessed with an online game. To encourage users to log in, this game will give users a continuous login reward. The mechanism of continuous login reward is as follows: If you have not logged in on a certain day, the reward of that day is 0, otherwise the reward is the previous day's plus 1.

On the other hand, Pierre is very fond of the number N. He wants to get exactly N points reward with the least possible interruption of continuous login.

Input

There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:

There is one integer N (1 <= N <= 123456789).

Output

For each test case, output the days of continuous login, separated by a space.

This problem is special judged so any correct answer will be accepted.

Sample Input

4
20
19
6
9

Sample Output

4 4
3 4 2
3
2 3

Hint

20 = (1 + 2 + 3 + 4) + (1 + 2 + 3 + 4)

19 = (1 + 2 + 3) + (1 + 2 + 3 + 4) + (1 + 2)

6 = (1 + 2 + 3)

9 = (1 + 2) + (1 + 2 + 3)

Some problem has a simple, fast and correct solution.

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue> int val[];
bool hash[];
struct node
{
int val;
int i;
struct node *next;
}f[]; void Insert(int x,int i)
{
int k;
node *p;
k=x%;
p=&f[k];
while(p!=NULL && p->val!=x)
{
p=p->next;
}
if(p==NULL)
{
p=(struct node*)malloc(sizeof(struct node));
p->val=x;
p->i=i;
p->next=f[k].next;
f[k].next=p;
}
}
bool found(int x,int &i)
{
int k;
node *p;
k=x%;
p=&f[k];
while(p!=NULL && p->val!=x)
{
p=p->next;
}
if(p==NULL) return false;
if(p->val==x)
{
i=p->i;
return true;
}
return false;
}
void prepare()
{
int i;
val[]=;
for(i=;i<=;i++)
{
f[i].val=;
f[i].i=;
f[i].next=NULL;
}
for(i=;i<=;i++)
{
val[i]=val[i-]+i;
Insert(val[i],i);
}
}
void solve(int n)
{
int i,wz,k,j,s;
//one
if(found(n,wz)==true)
{
printf("%d\n",wz);
return;
}
for(i=;;i--)
{
if(val[i]<n)
{
s=i;
break;
}
}
for(i=;i<=s;i++)
{
k=n-val[i];
if(found(k,wz)==true)
{
printf("%d %d\n",i,wz);
return;
}
}
for(i=;i<=s;i++)
{
for(j=s;j>=;j--)
{
k=n-val[i]-val[j];
if(k<)continue;
if(found(k,wz)==true)
{
printf("%d %d %d\n",i,j,wz);
return;
}
}
}
}
int main()
{
int T,n;
prepare();
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
solve(n);
}
return ;
}

zoj Continuous Login的更多相关文章

  1. zoj 3768 Continuous Login

    Pierre is recently obsessed with an online game. To encourage users to log in, this game will give u ...

  2. ZOJ3768 Continuous Login 2017-04-14 12:47 45人阅读 评论(0) 收藏

    Continuous Login Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge Pierre is rec ...

  3. 2014 Super Training #7 B Continuous Login --二分

    原题:ZOJ 3768 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3768 一个结论:一个正整数总能用不超过三个前n项相 ...

  4. ZOJ3768 夹逼查找【STL__lower_bound()_的应用】

    首先学习一下lower_bound() 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置.如果所有元素都小于val,则返回last ...

  5. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

  6. ZOJ 2112 Dynamic Rankings(主席树の动态kth)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 The Company Dynamic Rankings ...

  7. 高级数据结构(树状数组套主席树):ZOJ 2112 Dynamic Rankings

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  8. 详解OJ(Online Judge)中PHP代码的提交方法及要点【举例:ZOJ 1001 (A + B Problem)】

    详解OJ(Online Judge)中PHP代码的提交方法及要点 Introduction of How to submit PHP code to Online Judge Systems  Int ...

  9. ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

随机推荐

  1. Java基础学习篇---------封装

    一.类和对象分配内存 二.Java中的内部类  : 可以直接去访问外部类的所有属性(包括私有成员) 1.Java中成员内部类 (1).内部类的方法可以直接访问外部类的类中的所有成员变量 (2).外部类 ...

  2. (转)为什么要重写 hashcode 和 equals 方法?

    作者丨hsm_computer cnblogs.com/JavaArchitect/p/10474448.html 我在面试Java初级开发的时候,经常会问:你有没有重写过hashcode方法?不少候 ...

  3. Elasticsearch java API (23)查询 DSL Geo查询

    地理查询编辑 Elasticsearch支持两种类型的地理数据: geo_point纬度/经度对字段的支持,和 geo_shape领域,支持点.线.圆.多边形.多等. 这组查询: geo_shape  ...

  4. RabbitMQ交换机规则实例

    RabbitMQ Exchange分发消息时根据类型的不同分发策略有区别,目前共四种类型:direct.fanout.topic.headers .headers 匹配 AMQP 消息的 header ...

  5. 利用 URLProtocol 假冒一个服务器来测试网络

    制造一个假的服务器 class MockURLProtocol: URLProtocol { static var requestHandler: ((URLRequest) throws -> ...

  6. mysql 练习 和链接 pymysql 练习题

    python操作数据库 1. 查询student表的所有记录 2. 查询student表的第2条到第4条记录 3. 查询所有学生的学号(id).姓名(name)和报读课程(department)的信息 ...

  7. yii2之前端资源引入

     PS:因新项目后端使用yii2框架,不在使用纯html模板的方式搭建页面(前后端不分离模式)使用yii2的内置boostart封装模板,遂研究了一番yii2 通过yii2官方下载的基础文件结构 其中 ...

  8. SVN常用操作介绍

    SVN:全称subversion,开源代码版本控制系统,也就是常说的“版本控制工具”,实现代码.文档等的历史版本保存.共享和权限管理.常用于软件开发项目中,开发将最新的代码放到svn,其他同事可在这个 ...

  9. POJ 2304

    #include<iostream>// cheng da cai zi 11. 18 解锁问题 using namespace std; #define f 360 int main() ...

  10. Ant运行build.xml执行服务器scp,异常解决jsch.jar

    公司ant打包上线 一直出现这个问题. Ant运行build.xml执行服务器scp,异常解决jsch.jar BUILD FAILEDD:\eclipse\eclipse-jee-luna-SR2- ...