ZOJ 3768 Continuous Login(找规律+哈希)

来源:互联网 发布:淘宝链接突然间没有了 编辑:程序博客网 时间:2024/06/05 13:25

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 Npoints 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
4201969
<h4< dd="">
Sample Output
4 43 4 232 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.



题解:

列几组数据可以发现最多有3组组成一个数字,然后就打表,用map记录下该数字下是加到几的结果,然后分三种情况:第一种是一个数字就可以组成,这个直接哈希判断就好,第二种是两个数字组成,这个用枚举第一个数字+第二个哈希判断就好了,第三种是三个数字组成,枚举前两个第三个数字用哈希判断

代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#include<stdio.h>using namespace std;#define ll long longmap<int,int>M;int a[15750];void init(){    int i,j,s=0;    for(i=1;i<=15720;i++)    {        s+=i;        M[s]=i;        a[i]=s;    }}int main(){    int i,j,k,n,test,tag;    init();    while(scanf("%d",&test)!=EOF)    {        while(test--)        {            scanf("%d",&n);            if(M[n])            {                printf("%d\n",M[n]);            }            else            {                tag=0;                for(i=1;a[i]<n;i++)                {                    if(M[n-a[i]])                    {                        printf("%d %d\n",i,M[n-a[i]]);                        tag=1;                        break;                    }                }                if(!tag)                {                    for(i=1;a[i]<n;i++)                    {                        for(j=1;a[i]+a[j]<n;j++)                        {                            if(M[n-a[i]-a[j]])                            {                                printf("%d %d %d\n",i,j,M[n-a[i]-a[j]]);                                goto loop;                            }                        }                    }                    loop:;                }            }        }    }    return 0;}


阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 喜帖填写范例图片 结婚请贴填写范文 贫困申请表填写样本 现金日记账填写样本 支票日期填写规范 答题卡填写样本图片 收款收据填写样本 如何填写个人简历 差旅报销单填写 如何填写费用报销单 费用报销单填写 户籍怎么填写 出库单怎么填写 费用报销单填写规范 专业怎么填写 怎么填写记账凭证 简历表怎么填写 如何填写报销单 学位填写什么 email怎么填写 费用报销单填写格式 如何填写财务报表 考勤表怎么填写 高考怎么填写志愿 邮箱怎样填写 高考填写志愿指南 ds160填写指南 如何填写电子邮件地址 科目汇总表填写样本 电子邮箱怎么填写 就读方式怎么填写 高佣联盟从哪填写邀请码 从业情况怎么填写 健康状况怎么填写 户籍类型怎么填写 学生籍贯正确填写方式 报考类别怎么填写 开户银行怎么填写 高佣联盟怎么填写邀请码 高考志愿专业填写 费用报销单的填写