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)

题意:给出n求出最少要用多少等差数列的连续和组成。

sl:本以为是dp没想到n这么大,天啊,跳河,之后就没做,只敲了下dp代码看了看有没有什么规律。

打了表没看出来。后来才知道原来最终结果不超过3,再看看我的表确实如此。有表都没看出规律。

之后就是暴力枚举了。 时间复杂度是1e6刚好。

外付打表代码。

 1 //water
 2 /*
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 typedef long long LL;
 const int inf = 0x3f3f3f3f;
 const int MAX = 1e6+10;
 int dp[MAX];
 int main()
 {
     int n;
     while(scanf("%d",&n)==1)
     {
         for(int i=0;i<MAX;i++) dp[i]=inf;
         dp[1]=1; dp[0]=0;
         for(int i=2;i<100;i++)
         {
             for(int j=1;j<100;j++)
             {
                 int t=(i-j+1)*(1+i-j+1)/2;
                 if(t<=i)
                 dp[i]=min(dp[i],dp[i-t]+1);
             }
         }
         printf("%d\n",dp[n]);
     }
     return 0;
 }
 全然不超过3个
 */
 #include <cstring>
 #include <algorithm>
 #include <cstdio>
 #include <map>
 using namespace std;
 const int MAX = 1e6+;
 map<int,int> val;
 map<int,int> cnt;
 
 void init()
 {
     int start=; int cur=; int a=;
     while(start<=)
     {
         val[cur]=start;
         cnt[start]=cur;
         a++;
         start+=a;
         cur++;
     }
 }
 
 int main()
 {
     int cas,n;
     scanf("%d",&cas);
     while(cas--)
     {
         val.clear(); cnt.clear();
         init();
         scanf("%d",&n);
 
         if(cnt[n])
         printf("%d\n",cnt[n]);
         else
         {
             int end=; int flag=;
             while(val[end]<n) end++;
             for(int i=;i<=end;i++)
             {
                 if(val[n-val[i]])
                 {
                     flag=;
                     printf("%d %d\n",cnt[val[i]],cnt[n-val[i]]);
                 }
             }
             for(int i=;i<=end&&flag;i++)
             {
                 for(int j=end;j>=&&flag;j--)
                 {
                     int t=n-val[j]-val[i];
                     if(t>)
                     {
                         if(val[t])
                         {
                             printf("%d %d %d\n",cnt[val[i]],cnt[val[j]],cnt[t]);
                         }
                     }
                 }
             }
         }
     }
 
     return ;
 }

zoj 3768 Continuous Login的更多相关文章

  1. zoj Continuous Login

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

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

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

  3. 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 ...

  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. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

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

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

  9. 详解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 ...

随机推荐

  1. 10.12NOIP模拟题(1)

    #include<iostream> #include<cstdio> #include<cstring> #include<queue> #defin ...

  2. $Hdu1381\ Crazy\ Search$

    前置芝士 :string 的 基本用法 string s = "hello world" ; string tmp(s,0,5) ; cout << tmp <& ...

  3. 【js】再谈移动端的模态框实现

    移动端模态框的机制因为与PC的模态框机制一直有所区别,一直是许多新人很容易踩坑的地方,最近笔者作为一条老咸鱼也踩进了一个新坑中,真是平日里代码读得太粗略,故而写上几笔,以儆效尤. 故事的起因是这样的, ...

  4. [转]C++常用字符串分割方法实例汇总

    本文实例汇总了C++常用字符串分割方法,分享给大家供大家参考.具体分析如下: 我们在编程的时候经常会碰到字符串分割的问题,这里总结下,也方便我们以后查询使用. 一.用strtok函数进行字符串分割 原 ...

  5. 用 NPOI 组件实现数据导出

    利用 Nuget 安装 NPOI 组件. 所需引用的 dll:ICSharpCode.SharpZipLib.dll.NPOI.dll.NPOI.OOXML.dll.NPOI.OpenXml4Net. ...

  6. Redis基础---消息通信模式

    Redis发送订阅通信模式 Redis发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 发布订阅(pub/sub)实现了消息系统,发送者( ...

  7. 在idea中为类和方法自动生成注释

    https://my.oschina.net/mojiayi/blog/1608746

  8. 网页内容爬取:如何提取正文内容 BEAUTIFULSOUP的输出

    创建一个新网站,一开始没有内容,通常需要抓取其他人的网页内容,一般的操作步骤如下: 根据url下载网页内容,针对每个网页的html结构特征,利用正则表达式,或者其他的方式,做文本解析,提取出想要的正文 ...

  9. Farseer.net轻量级开源框架 中级篇:DbFactory数据工厂

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 执行SQL语句 下一篇:Farseer.net轻量级开源框架 中级篇: 数据绑定 ...

  10. CNN:测试一下YoloV3

    项目地址:https://pjreddie.com/darknet/yolo/ mAP提升了不少,在VS上试一把 V3 的权值: https://pjreddie.com/media/files/yo ...