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 ...
随机推荐
- Organising the Organisation(uva10766)(生成树计数)
Input Output Sample Input 5 5 2 3 1 3 4 4 5 1 4 5 3 4 1 1 1 4 3 0 2 Sample Output 3 8 3 题意: 有一张图上有\( ...
- daemon_int
摘自 UNP #include "unp.h" #include <syslog.h> #define MAXFD 64 extern int daemon_proc; ...
- falcon nodata 小坑一枚
按照官方文档配置完一切正常,唯独 nodata, 明明有正常的数据,但是为什么 nodata 会认为是没收到呢 困扰许久,直到看了数据库中的数据才恍然大悟 falcon_portal库中的 hosts ...
- 【javascript】iOS Safari 中点击事件失效的解决办法
问题描述 当使用委托给一个元素添加click事件时,如果事件是委托到 document 或 body 上,并且委托的元素是默认不可点击的(如 div, span 等),此时 click 事件会失效. ...
- 详解linux下的串口通讯开发
串行口是计算机一种常用的接口,具有连接线少,通讯简单,得到广泛的使用.常用的串口是RS-232-C接口(又称EIA RS-232-C)它是在1970年由美国电子工业协会(EIA)联合贝尔系统.调制解调 ...
- WPF一步步开发XMPP IM客户端1:入门
[起因&目标] 因为工作原因接触openfire服务端和spark客户端开发,主要是基于openfire扩展开发了针对企业用途的服务器插件,还开发了各个平台上的客户端(Windows\mac\ ...
- Xshell连接不上虚拟机Linux系统
以下是我在尝试网上各种办法之后总结的最优解决办法: 1.先在主机上检查虚拟机相关的必要的服务是否都已经启动 2.检查虚拟机系统防火墙是否处于关闭状态 3.检查虚拟机系统的ssh服务是否已经启动 4.检 ...
- easyui datagrid里的复选框置灰方法
easyui datagrid里的复选框置灰方法: $('.datagrid input').prop('disabled',true);//复选框置灰
- 搭建互联网架构学习--003--maven以及nexus私服搭建
跳过,等待完善中,,, 后台服务工具maven:使用Nexus配置Maven私有仓库 一.安装配置Nexus 1. 下载nexus https://www.sonatype.com/download- ...
- PreparedStatement插入values
public interface PreparedStatementextends Statement 表示预编译的 SQL 语句的对象. SQL 语句被预编译并存储在 PreparedStateme ...