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 ...
随机推荐
- springboot(二)整合mybatis,多数据源和事务管理
-- 1.整合mybatis -- 2.整合多数据源 -- 3. 整合事务 代码地址:https://github.com/showkawa/springBoot_2017/tree/master/ ...
- 转:python中使用txt文本保存和读取变量
问题: 在python中需要经常有需要提前生成复杂的计算结果变量的需求减少程序计算运行时间的需求,因此这里把变量存在txt文本文件中. 解决方法: 使用两个函数解决问题,一个函数把变量保存到文本文件中 ...
- 386 Lexicographical Numbers 字典序排数
给定一个整数 n, 返回从 1 到 n 的字典顺序.例如,给定 n =1 3,返回 [1,10,11,12,13,2,3,4,5,6,7,8,9] .请尽可能的优化算法的时间复杂度和空间复杂度. 输入 ...
- [译]libcurl_tutorial
Handle the Easy libcurl To use the easy interface, you must first create yourself an easy handle. Yo ...
- asp.net MVC Session 第二次加载丢失问题
在做本地调试时发现,session 加载过了对象之后,每次都是第一次加载成功,第二次再进来时候session 就是失效丢失了,究其原因:原来是因为第一次加载session 过大导致,原有其他sessi ...
- [ CodeForces 515 D ] Drazil and Tiles
\(\\\) \(Description\) 给出一个\(N\times M\) 的网格,一些位置是障碍,其他位置是空地,求是否存在一个用 \(1\times 2\)的骨牌铺满空地的方案,以及方案是否 ...
- 2017-12-04HTML table布局
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 计算机二级C语言冲刺笔记。
2018-03-0618:32:26 风萧萧兮易水寒,壮士一去...... 四级依旧没过,计算机二级接踵而至, default语句在switch语句中可以省略,所以B错误:switch语句中并非每个c ...
- Server 2008 R2 事件查看器实现日志分析
在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...
- Angular——配置模块与运行模块
配置模块 通过config方法实现对模块的配置,AngularJS中的服务大部分都对应一个“provider”,用来执行与对应服务相同的功能或对其进行配置.比如$log.$http.$location ...