题意:按下列规则生成一组序列,令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. Largest Rectangle in a Histogram 杭电1506

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=1506 Problem Description A histogram is a polygon co ...

  2. Redis 5.0.9 安装

    目录 系统环境 系统版本 内核版本 安装步骤 安装 gcc 依赖 下载 Redis 解压 Redis 切换到 redis 解压目录下,执行编译 指定目录安装 启动 Redis 服务 最后 系统环境 系 ...

  3. 2020/4/26 大数据的zookeeper分布式安装

    大数据的zookeeper分布式安装 **** 前面的文章已经提到Hadoop的伪分布式安装.现在就在原有的基础上安装zookeeper. 首先启动Hadoop平台 [root@master ~]# ...

  4. Dockerfile的简单人门编写之关于yum的问题

    首先我们编写一个简单的Dockerfile的例子.不过再此之前大家得去把编写dockerfile的指令了解一下. 编写以 centos镜像为基础镜像,构建 http 服务,Dockerfile 要求删 ...

  5. pytorch 孪生神经网络DNN

    代码内容请见: https://github.com/LiuXinyu12378/DNN-network

  6. windows 系统查看NVIDIA显卡GPU情况,nvidia-smi在windows上使用

    cd C:\Program Files\NVIDIA Corporation\NVSMI nvidia-smi   当batch_size设置越大的时候,GPU加速越明显,但是batch_size设置 ...

  7. UnicodeDecodeError: 'gbk' codec can't decode byte 0x8a in position 2: illegal multibyte sequence

    pycharm报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8a in position 2: illegal multibyte seq ...

  8. Python网络爬虫:伪装浏览器

    一.添加超时跳过功能 首先, 我简单地将 urlop = urllib.request.urlopen(url) 改为 urlop = urllib.request.urlopen(url, time ...

  9. 头文件<cmath>中常用函数

    <cmath>里面有很多数学函数,下面说一下常用的一些函数吧:直接把函数原型给了出来,用的时候注意参数 先说一下,c++自身是没有四舍五入函数round()的,若果你要用到的话,可以自己写 ...

  10. python学习笔记(三)---字典

    字典 在Python中,字典 字典 是一系列键 键-值对 值对 .每个键 键 都与一个值相关联,你可以使用键来访问与之相关联的值.与键相关联的值可以是数字.字符串.列表乃至字典.事实上,可将 任何Py ...