题意:按下列规则生成一组序列,令f(n)为n这个数在序列中出现的最后一个位置,求f(f(n))的值。

1. First, write down 1, 2 on a paper.
2. The 2nd number is 2, write down 2 2’s (including the one originally on the paper). The paper thus has 1, 2, 2 written on it.
3. The 3rd number is 2, write down 2 3’s. 1, 2, 2, 3, 3 is now shown on the paper.
4. The 4th number is 3, write down 3 4’s. 1, 2, 2, 3, 3, 4, 4, 4 is now shown on the paper.
5. The procedure continues indefinitely as you can imagine. 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, . . . .

思路:令原序列为a,根据定义和序列的生成规则可以推出:

  • f(n)等于a的前n项和
  • f(n)是n这个数在a中出现的最后一个位置

f(f(n))的含义为:a的前m项和,m为n在a中最后出现的位置。所以f(f(n))的计算式可以写成:

f(f(n))=1 + (2+3)*2 + (4+5)*3 + (6+7+8)*4 + ... + (...+n)*t

t是远小于n的,大概为几十万的样子,剩下的就不多说了。。。

#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>
using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii; namespace Debug {
void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<" ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
}
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
/* -------------------------------------------------------------------------------- */ const int maxn = 1e9 + ;
const int mod = maxn; int seq[] = {, , , };
ll sum[] = {, , , }, ans[];
int total = ;
void init() {
for (int i = ; ; i ++) {
for (int j = ; j < seq[i]; j ++) {
seq[++ total] = i;
sum[total] = sum[total - ] + seq[total];
}
if (sum[total] > maxn) break;
}
ans[] = ;
for (int i = ; i < total; i ++) {
ans[i] = (ans[i - ] + (sum[i] + sum[i] - seq[i] + ) * seq[i] / % mod * i) % mod;
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, n;
init();
cin >> T;
while (T --) {
cin >> n;
int p = upper_bound(sum + , sum + total, n) - sum - ;
cout << (ans[p] + (sum[p] + + n) * (n - sum[p]) / % mod * (p + )) % mod << endl;
}
}

[hdu5439 Aggregated Counting]公式化简,预处理的更多相关文章

  1. Aggregated Counting(找规律 + 预处理)

    Aggregated Counting 转 : https://blog.csdn.net/cq_phqg/article/details/48417111 题解: 可以令n=1+2+2+3+3+.. ...

  2. Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)

    题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最 ...

  3. [zoj3813]Alternating Sum 公式化简,线段树

    题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...

  4. HDU 5439 Aggregated Counting

    题目大意: 由1开始不断往数组中添加数 就是按照当前所在位置所在的数表示的个数添加这个数目的数 1 2 2 3 3 后面因为要填4,而4号位置为3,说明之后要填3个4 问题就是给定一个n,找到n出现的 ...

  5. UVALive-8079 Making a Team 排列组合公式化简

    题目链接:https://cn.vjudge.net/problem/UVALive-8079 题意 n个人组队,队伍人数小于等于n,每个队伍需要4个不同的职务的领导. 问这n个人可以组成多少队? n ...

  6. [hdu5448 Marisa’s Cake]多边形面积,公式化简

    题意:给一个凸多边形,求任选若干点形成的多边形的面积和. 思路: 按一定方向(顺时针或逆时针)对多边形的顶点进行编号,则多边形的面积计算公式为:f1 x f2 + f2 x f3 + ... fn-1 ...

  7. [HDOJ5439]Aggregated Counting(乱搞)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5439 题意:按规则构造一个数列a a(1)=1 a(2)=2 a(2)=2 -------> 写两个 ...

  8. HDU 4565 So Easy!(公式化简+矩阵)

    转载:http://www.klogk.com/posts/hdu4565/ 这里写的非常好,看看就知道了啊. 题意很easy.a,b,n都是正整数.求 Sn=⌈(a+b√)n⌉%m,(a−1)2&l ...

  9. HDU-4035-概率dp-期望-公式化简

    Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

随机推荐

  1. Maven 命令深度理解

    1.前言 Maven 命令看起来简单,一学即会 .其实,Maven 命令底层是插件的执行过程.了解插件和插件目标才有助于深刻的理解 Maven命令. 2.插件与命令的关系 Maven本质上是一个插件框 ...

  2. secureCRT常用操作

    直接在网上搜索下载 连接 选择协议 Telnet Telnet连接时,进入输入密码 串口 连接串口后,查看本机连接的串口号 新建的时候,选择相同的串口号 RTS需要勾选掉 外观字体 选项 => ...

  3. JACTF Web部分

    掘安团队的题目 平台已不运营 Web签到 发现请求URL为flag.php,但是会跳转到404.php页面,抓包发现有302重定向,查看响应包,flag经过base64编码,解码即可 Tips: 重定 ...

  4. C# 基础知识系列- 13 常见类库介绍(一)

    0. 前言 每篇一个前言,介绍一下这一篇的内容.之前的内容都是针对某些知识点进行的介绍,这篇内容介绍一下实际开发中常用的一些类和命名空间.这一篇是个连续剧,大概有个三四集.嗯,就是这样. 1. Sys ...

  5. Python中的可视化神器!你知道是啥吗?没错就是pyecharts!

    pyecharts是一款将python与echarts结合的强大的数据可视化工具,本文将为你阐述pyecharts的使用细则 前言 我们都知道python上的一款可视化工具matplotlib,而前些 ...

  6. 2层感知机(神经网络)实现非线性回归(非线性拟合)【pytorch】

    import torch import numpy import random from torch.autograd import Variable import torch.nn.function ...

  7. Golang快速入门:从菜鸟变大佬

    最近写了不少Go代码,但是写着写着,还是容易忘,尤其是再写点Python代码后.所以找了一篇不错的Golang基础教程,翻译一下,时常看看. 原文链接: 「Learning Go - from zer ...

  8. Kubernetes 命令行工具之kubctl

    目录 1.何为kubectl 2.Kubectl基本使用 2.1.命令补全 2.2.快速查找资源 2.3.使用自定义输出格式 3.陈述式管理资源 3.1.管理namespace资源 3.2.管理Dep ...

  9. Copy ArrayList的四种方式

    目录 简介 使用构造函数 使用addAll方法 使用Collections.copy 使用stream 总结 Copy ArrayList的四种方式 简介 ArrayList是我们经常会用到的集合类, ...

  10. 字符串translate方式实现

    在爬取百度图片的时候,发现百度图片做了反爬虫处理,在网上找到当前还能跑通的教程实例:python3多线程下载百度图片搜索结果. 在分析代码的过程中,发现作者对爬取的objURL的解码是通过字符串的tr ...