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.


题目的意思是给出一个数n是的n分成若干的数的和,每个数是重1累加奥x的,保证数字个数最少

找规律发现最多出现3项,分别对1项2项3项讨论,枚举加二分

#include <iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include <cstring>
using namespace std;
#define LL long long
int a[100005]; int main()
{
int T,n;
a[0]=0;
for(int i=1;i<100005;i++)
a[i]=a[i-1]+i;
scanf("%d",&T);
while(T--)
{
int flag=0;
scanf("%d",&n);
for(int i=0;i<100000;i++)
{
if(a[i]==n){
flag=1;
printf("%d\n",i);
break;
}
if(a[i]>n) break;
} if(flag) continue;
for(int i=0;a[i]<n;i++)
{
int x=n-a[i];
int pos=lower_bound(a,a+100000,x)-a;
if(a[pos]==x)
{
flag=1;
printf("%d %d\n",i,pos);
break;
}
}
if(flag) continue;
for(int i=0;a[i]<n;i++)
{
for(int j=0;a[j]<n-a[i];j++)
{
int x=n-a[i]-a[j];
int pos=lower_bound(a,a+100000,x)-a;
if(a[pos]==x)
{
flag=1;
printf("%d %d %d\n",i,j,pos);
break;
}
}
if(flag) break;
} } return 0;
}

ZOJ3768 Continuous Login 2017-04-14 12:47 45人阅读 评论(0) 收藏的更多相关文章

  1. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  2. Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏

    哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  3. ios UIKit动力 分类: ios技术 2015-07-14 12:55 196人阅读 评论(0) 收藏

    UIkit动力学是UIkit框架中模拟真实世界的一些特性. UIDynamicAnimator 主要有UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性. 它一般有两种初始 ...

  4. ZOJ3770Ranking System 2017-04-14 12:42 52人阅读 评论(0) 收藏

    Ranking System Time Limit: 2 Seconds      Memory Limit: 65536 KB Few weeks ago, a famous software co ...

  5. Log4j 2使用教程 分类: B1_JAVA 2014-07-01 12:26 314人阅读 评论(0) 收藏

    转载自 Blog of 天外的星星: http://www.cnblogs.com/leo-lsw/p/log4j2tutorial.html Log4j 2的好处就不和大家说了,如果你搜了2,说明你 ...

  6. .net 实现Office文件预览 Word PPT Excel 2015-01-23 08:47 63人阅读 评论(0) 收藏

    先打个广告: .Net交流群:252713569 本人QQ :524808775 欢迎技术探讨, 近期公司要求上传的PPT和Word都需要可以在线预览.. 小弟我是从来没有接触过这一块的东西 感觉很棘 ...

  7. Speed Limit 分类: POJ 2015-06-09 17:47 9人阅读 评论(0) 收藏

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17967   Accepted: 12596 Des ...

  8. 单链表操作B 分类: 链表 2015-06-07 12:42 15人阅读 评论(0) 收藏

    数据结构上机测试2-2:单链表操作B TimeLimit: 1000ms Memory limit: 65536K 题目描述 按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除 ...

  9. hdu 1035 (usage of sentinel, proper utilization of switch and goto to make code neat) 分类: hdoj 2015-06-16 12:33 28人阅读 评论(0) 收藏

    as Scott Meyers said in his book Effective STL, "My advice on choosing among the sorting algori ...

随机推荐

  1. vue项目修改favicon

    首先你的在你的static文件中添加favicon.icon 然后通过以下方式进行修改 1)方式一:修改index.html文件 <link rel="shortcut icon&qu ...

  2. Oracle.DataAccess.dll 部署安装

    Oracle.DataAccess.dll 要拷贝到项目发布目录 项目发布的时候,还必须要拷贝以下几个文件在运行目录1.oci.dll 2.oraociicus11.dll 3.OraOps11w.d ...

  3. [Android] 开发第八天

    View 类是所有 UI组件的基类,它包含的 XML 属性和方法是所有组件都可使用的. ViewGroup 继承了 View 类,主要当作容器类使用,它是一个抽象类,实际使用中会使用它的子类作为容器. ...

  4. jQuery ajax 当async为false时解决同步操作失败的问题

    jQuery的ajax,当async为false时,同步操作失败.解决方案,jqueryasync 最近做项目遇到jQuery的ajax,当async为false时,同步操作失败的问题,上网搜索下,得 ...

  5. java 工具类 static

    http://wenwen.sogou.com/z/q526955586.htm 工具类其实就是提供了一些公共的函数,方便其他类去调用,函数都写成static一方面是因为方便,另一方面是工具类的函数是 ...

  6. Nginx实战入门教程

    Nginx 简介 Nginx是一个高性能的http和反向代理服务器,它看起来好像不太符合英文单词的拼写习惯,因为Nginx是由名为 伊戈尔·赛索耶夫 的俄罗斯人开发的.Nginx主要特点为占用内存小, ...

  7. Java并发编程-Thread类的使用

    在前面2篇文章分别讲到了线程和进程的由来.以及如何在Java中怎么创建线程和进程.今天我们来学习一下Thread类,在学习Thread类之前,先介绍与线程相关知识:线程的几种状态.上下文切换,然后接着 ...

  8. Kafka学习之broker配置(0.8.1版)(转)

    broker.id  默认值:无 每一个broker都有一个唯一的id,这是一个非负整数,这个id就是broker的"名字",这样就允许broker迁移到别的机器而不会影响消费者. ...

  9. UNITY_INITIALIZE_OUTPUT宏

    UNITY_INITIALIZE_OUTPUT宏 UNITY_INITIALIZE_OUTPUT(type,name) –此宏用于将给定类型的名称变量初始化为零.在使用旧版标准所写的Shader时,经 ...

  10. 使screen支持滚动

    在Linux中,常用的串口工具有minicom和screen,minicom可能使用得比较多,但是我比较喜欢screen,因为它的输出是彩色的,更舒服.更能突出重点. 使用screen来打开串口也非常 ...