zoj 3768 Continuous Login
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的更多相关文章
- zoj Continuous Login
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 Continuous Login 2017-04-14 12:47 45人阅读 评论(0) 收藏
Continuous Login Time Limit: 2 Seconds Memory Limit: 131072 KB Special Judge Pierre is rec ...
- 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 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 高级数据结构(树状数组套主席树):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 ...
随机推荐
- P3626 [APIO2009]会议中心
传送门 好迷的思路-- 首先,如果只有第一问就是个贪心,排个序就行了 对于第二问,我们考虑这样的一种构造方式,每一次都判断加入一个区间是否会使答案变差,如果不会的话就将他加入别问我正确性我不会证 我们 ...
- [App Store Connect帮助]六、测试 Beta 版本(3.3)管理测试员:查看测试员信息
如果您使用“TestFlight Beta 版测试”,您可以查看关于测试员的信息,并衡量测试员的参与度. 必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能.“开发者”职能或“营销”职能 ...
- EntityFramework:An error occurred while executing the command definition. See the inner exception for details.
错误描述: 调用EF中的FirstOrDefault()时,报错误:An error occurred while executing the command definition. See the ...
- spring cloud config搭建说明例子(二)-添加eureka
添加注册eureka 服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</ ...
- mysql-5.7.20基本用法
第1章 安装mysql-5.7.20 1.1 系统环境 [root@mysql ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (C ...
- 数学 FZU 2074 Number of methods
题目传送门 /* 数学:假设取了第i个,有C(n-1)(i-1)种取法 则ans = sum (C(n-1)(i-1)) (1<i<=n) 即2^(n-1) */ #include < ...
- TCP/IP 3握手4挥手
转:摘自<图解TCP/IP>P204 三次握手与四次挥手的状态转移图如下: 如图,由于第二次握手接收端发送SYN+ACK信号所以握手只用了三次,挥手由于接收端ACK和FIN分两次发的,所以 ...
- python实现qq机器人qqbot
title: python实现qq机器人qqbot tags: python date: 2018-6-1 10:19:00 --- 以下内容为转载 一.介绍 qqbot 是一个用 python 实现 ...
- iOS布局分类
1.线性布局: 2.集合布局: 3.单元布局: 需要考虑因素: 空间充足.空间不足时内容.尺寸的取舍.
- ThinkPHP---AR模式
[前言] 在之前学习框架时介绍过 (1)什么是框架? ①框架是一堆包含了常量.方法和类等代码集合: ②半成品应用,只包含了项目开发时的底层架构,并不包含业务逻辑: ③包含一些设计模式,例如单例模式,工 ...