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 ...
随机推荐
- bzoj4534: 基础排序算法练习题
传送门 策爷的论文题啊……题解在这儿 我只想知道为什么这题的弱化版会出现在我们今天的%你赛里…… 题意:给你一堆操作$(l,r)$,表示将区间$(l,r)$按升序排序.以及$q$个询问,每次询 ...
- 微信小程序获取自定义属性值
写小程序的时候用到了自定义属性,特地来记录一下 特别是这个坑,必须得说一说 wxml <view class='box' bindtap='getValue'> <view clas ...
- [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列
Description N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色,每头牛有多种特色,用二进制01表示它的特色ID.比如特色ID为13(1101),则 ...
- [Usaco2015 Jan]Moovie Mooving
Description Bessie is out at the movies. Being mischievous as always, she has decided to hide from F ...
- 1、DOS基本命令
命令dir能给列出当前目录下面的所有文件.程序和子目录.所有目录(Windows 中称为文件夹)的目录名前面都有一个<DIR>标记.文件和程序名前面显示有这些文件和程序的大小. 想说的是, ...
- Ajax动态加载数据
前言: 1.这个随笔实现了一个Ajax动态加载的例子. 2.使用.net 的MVC框架实现. 3.这个例子重点在前后台交互,其它略写. 开始: 1.控制器ActionResult代码(用于显示页面) ...
- Unity笔记(3)自学第二天
学习记录: 界面使用: 脚本使用: 脚本注意点:
- Django基础之admin功能
Django默认开起了后台 1.访问admin后台 2.用户和密码进行登录 ============================================================== ...
- 鼠标拖拽移动Java界面组件
默认的,Frame或者JFrame自身已经实现了鼠标拖拽标题栏移动窗口的功能. 只是,当你不满意java的JFrame样式,隐藏了标题栏和边框,又或者干脆直接使用JWindow,那你又该怎么实现鼠标拖 ...
- 北大ACM(POJ1017-Packets)
Question:http://poj.org/problem?id=1017 问题点:贪心. Memory: 224K Time: 32MS Language: C++ Result: Accept ...