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 ...
随机推荐
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】
从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cst ...
- js 本地存储 localStorage 之 angular
今天项目中用到 php yii框架 用的不是 angular路由 所以用rootScope传值是不行的 我就用到了 localStorage 本地持久化存储 如下 set 顾名思义是设置 值 loca ...
- [App Store Connect帮助]六、测试 Beta 版本(3.1)管理测试员:添加内部测试员
您可以添加至多 25 个内部测试员(您的 App Store Connect 用户)使用“TestFlight Beta 版测试”来测试您的 App.在您上传了至少一个构建版本之后,才可添加测试员. ...
- 从 C++ 到 Objective-C 的快速指南
简介 当我开始为iOS写代码的时候,我意识到,作为一个C++开发者,我必须花费更多的时间来弄清楚Objective-C中怪异的东西.这就是一个帮助C++专家的快速指南,能够使他们快速的掌握Apple的 ...
- request获取请求参数
/** * 方式1 */ Enumeration<?> enu=request.getParameterNames(); while(enu.hasMoreElements()){ Str ...
- 理解 CSS 布局和块级格式上下文
前言 BFC 的概念始于 CSS2,是个蛮古老的 CSS 话题了,网上也到处能搜到 BFC 的介绍,但是都不够简洁.本文系翻译自 Rachel Andrew 女士的博文 Understanding C ...
- bootstrap3无间距栅格/grid no-gutter
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 安卓开发常用网络请求框架OkHttp、Volley、XUtils、Retrofit对比
网络请求框架总结1.xutils 此框架庞大而周全,这个框架可以网络请求,同时可以图片加载,又可以数据存储,又可以 View 注解,使用这种框架很方便,这样会使得你整个项目对它依赖性太强,万一 ...
- Eclipse+JUnit+Selenium配置
运行环境:Windows XP.Firefox.Firefox需要安装在标准路径下"C:\Program Files\Mozilla Firefox\firefox.exe",否则 ...
- HDU_1022_Train Problem I
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...