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. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(1)App Store 图标、App 预览和屏幕快照概述

    您可以为您的 App Store 产品页提供有关您 App 的 App Store 图标.三个 App 预览和十张屏幕快照. App Store 图标 您必须提供一个 App Store 图标,用于在 ...

  2. webservice 权限控制

    webservice 如何限制访问,权限控制?1.服务器端总是要input消息必须携带用户名.密码信息 如果不用cxf框架,SOAP消息(xml片段)的生成.解析都是有程序员负责 2.拦截器 为了让程 ...

  3. [洛谷3930]SAC E#1 - 一道大水题 Knight

    Description 他们经常在一起玩一个游戏,不,不是星际争霸,是国际象棋.毒奶色觉得F91是一只鸡.他在一个n×n的棋盘上用黑色的城堡(车).骑士(马).主教(象).皇后(副).国王(帅).士兵 ...

  4. 状压DP UVA 10817 Headmaster's Headache

    题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...

  5. ACM_01背包2

    背包4 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有n个重量和价值分别为Wi,Vi的物品,现从这些物品中挑选出总量不超过W的 ...

  6. .NET 错误 47 存储区提供程序工厂类型“Oracle.DataAccess.Client.OracleClientFactory”未实现 IServiceProvider 接口。请使用实现该接口的存储区提供程序。

    问题描述: 最近用VS2010连接ORACLE数据库的时候突然报错“错误 47 存储区提供程序工厂类型“Oracle.DataAccess.Client.OracleClientFactory”未实现 ...

  7. UUID 生成32位随机串

    java通过jdk自带的UUID,生成32位的随机串 private static String generate_UUID() { UUID uuid=UUID.randomUUID(); Stri ...

  8. Docker在Ubuntu16.04上安装

    转自:http://blog.51cto.com/collen7788/2047800 1.添加Docker源 sudo apt-get update 2.增加CA证书 sudo apt-get in ...

  9. jboss之启动加载过程详解

    今天看了看jboss的boot.log和server.log日志,结合自己的理解和其他的资料,现对jboss的启动和加载过程做出如下总结: boot.xml是服务器的启动过程的日志,不涉及后续的操作过 ...

  10. Spring框架系列(九)--MyBatis面试题(转载)

    1.什么是Mybatis? 1.Mybatis是一个半ORM(对象关系映射)框架,它内部封装了JDBC,开发时只需要关注SQL语句本身,不需要花费精力去处理加载驱动.创建 连接.创建statement ...