zoj Continuous Login
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.
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue> int val[];
bool hash[];
struct node
{
int val;
int i;
struct node *next;
}f[]; void Insert(int x,int i)
{
int k;
node *p;
k=x%;
p=&f[k];
while(p!=NULL && p->val!=x)
{
p=p->next;
}
if(p==NULL)
{
p=(struct node*)malloc(sizeof(struct node));
p->val=x;
p->i=i;
p->next=f[k].next;
f[k].next=p;
}
}
bool found(int x,int &i)
{
int k;
node *p;
k=x%;
p=&f[k];
while(p!=NULL && p->val!=x)
{
p=p->next;
}
if(p==NULL) return false;
if(p->val==x)
{
i=p->i;
return true;
}
return false;
}
void prepare()
{
int i;
val[]=;
for(i=;i<=;i++)
{
f[i].val=;
f[i].i=;
f[i].next=NULL;
}
for(i=;i<=;i++)
{
val[i]=val[i-]+i;
Insert(val[i],i);
}
}
void solve(int n)
{
int i,wz,k,j,s;
//one
if(found(n,wz)==true)
{
printf("%d\n",wz);
return;
}
for(i=;;i--)
{
if(val[i]<n)
{
s=i;
break;
}
}
for(i=;i<=s;i++)
{
k=n-val[i];
if(found(k,wz)==true)
{
printf("%d %d\n",i,wz);
return;
}
}
for(i=;i<=s;i++)
{
for(j=s;j>=;j--)
{
k=n-val[i]-val[j];
if(k<)continue;
if(found(k,wz)==true)
{
printf("%d %d %d\n",i,j,wz);
return;
}
}
}
}
int main()
{
int T,n;
prepare();
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
solve(n);
}
return ;
}
zoj Continuous Login的更多相关文章
- zoj 3768 Continuous Login
Pierre is recently obsessed with an online game. To encourage users to log in, this game will give u ...
- 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 ...
- 2014 Super Training #7 B Continuous Login --二分
原题:ZOJ 3768 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3768 一个结论:一个正整数总能用不超过三个前n项相 ...
- ZOJ3768 夹逼查找【STL__lower_bound()_的应用】
首先学习一下lower_bound() 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置.如果所有元素都小于val,则返回last ...
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
- ZOJ 2112 Dynamic Rankings(主席树の动态kth)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 The Company Dynamic Rankings ...
- 高级数据结构(树状数组套主席树):ZOJ 2112 Dynamic Rankings
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- 详解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 ...
- ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
随机推荐
- jqury的ajax
前端代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- 华为交换机 查看 ip和mac对应关系
IPv4: display arp IPv6: display ipv6 neighbors
- 《Python黑帽子:黑客与渗透测试编程之道》 扩展Burp代理
下载jython,在Burpsuite的扩展中配置jython路径: Burp模糊测试: #!/usr/bin/python #coding=utf-8 # 导入三个类,其中IBurpExtender ...
- rawt
这里写自定义目录标题 欢迎使用Markdown编辑器 新的改变 功能快捷键 合理的创建标题,有助于目录的生成 如何改变文本的样式 插入链接与图片 如何插入一段漂亮的代码片 生成一个适合你的列表 创建一 ...
- 一种基于zookeeper的分布式队列的设计与实现
package com.ysl.zkclient.queue; import com.ysl.zkclient.ZKClient; import com.ysl.zkclient.exception. ...
- Android中获取系统内存信息以及进程信息-----ActivityManager的使用(一)
本节内容主要是讲解ActivityManager的使用,通过ActivityManager我们可以获得系统里正在运行的activities,包括 进程(Process)等.应用程序/包.服务(Serv ...
- Codeforces Round #556 (Div. 2)
比赛链接 A 贪心 #include <cstdlib> #include <cstdio> #include <algorithm> #include <c ...
- KBEngine 安装
其实这篇的内容官方文档都有, 但是既然打算记录一下学习笔记, 也就先从安装开始了. 一 下载源代码 进入github下载最新release的源码压缩包. windows选择zip, 下载完成之后右键解 ...
- 剑指offer五十八之对称的二叉树
一.题目 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的.二.思路 递归做,详见代码 三.代码 /* public class TreeN ...
- Spark之Scala学习
1. Scala集合学习: http://blog.csdn.net/lyrebing/article/details/20362227 2. scala实现kmeans算法 http://www.t ...