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. 开车旅行 2012年NOIP全国联赛提高组(倍增+set)

    开车旅行 2012年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description 小A 和小B决定利用 ...

  2. SQL 经典语句大全

    原地址:http://www.cnblogs.com/yubinfeng/archive/2010/11/02/1867386.html 一.基础 1.说明:创建数据库 CREATE DATABASE ...

  3. 洛谷 P2090 数字对

    发现如果给定两个数(a,b),可以用类似辗转相除法在logn的时间内计算出(反向)变到(1,1)的最小步数. 然而并不知道另一个数是多少? 暴力嘛,枚举一下另一个数,反正1000000的nlogn不虚 ...

  4. Hadoop Hive概念学习系列之hive的索引及案例(八)

    hive里的索引是什么? 索引是标准的数据库技术,hive 0.7版本之后支持索引.Hive提供有限的索引功能,这不像传统的关系型数据库那样有“键(key)”的概念,用户可以在某些列上创建索引来加速某 ...

  5. RabbitMQ~广播消息

    定义 广播消息是指生产者产生的消息将分发给所有订阅这个消息的消费者,而普通的模式是:一批消息可以被多个人共同消费,如consumer1可能消费1,3,5记录,而consumer2可能消费的是2,4,6 ...

  6. 面向过程与面向对象引入三大特性&&事务

    1.面向过程 int a = 10;int b =5;int c = a+b; int r1 = 10;int r2 = 5;double c = r1*r1*3.14 - r2*r2*3.14 缺点 ...

  7. EasyUI系列学习(五)-Resizable(调整大小)

    一.创建组件 1.使用标签创建可变大小的窗口 <div id="rBox" class="easyui-resizable" style="wi ...

  8. JAVA使用Ldap操作AD域

    项目上遇到的需要在集成 操作域用户的信息的功能,第一次接触ad域,因为不了解而且网上其他介绍不明确,比较费时,这里记录下. 说明: (1). 特别注意:Java操作查询域用户信息获取到的数据和域管理员 ...

  9. navicat创建存储过程报错

    搞了半天这个恶心的报错,最后发现竟然是存储过程的一个varchar类型的参数没给长度,如varchar(64)长度必须指定不然就会报错: mark一记

  10. 【sqli-labs】 less61 GET -Challenge -Double Query -5 queries allowed -Variation4 (GET型 挑战 双查询 只允许5次查询 变化4)

    http://192.168.136.128/sqli-labs-master/Less-61/?id=1' 单引号双括号闭合 192.168.136.128/sqli-labs-master/Les ...