题意:按下列规则生成一组序列,令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. Mac 安装 brew(最新教程,绝对可行)

    现在安装brew,一会报这个错,一会儿报那个错,上网查了很多教程,用了很多时间都是不可以,电脑开VPN翻墙也不行. Warning: The Ruby Homebrew installer is no ...

  2. 它来了!它来了!Seata Go Client 它来了!!!

    抱歉抱歉,这个标题一看就是个很标题党的标题.本文所述的 Seata Go Client 只支持 TCC 模式,并不像 Java 版的能支持到 AT 模式.SAGA 模式.XA 模式,聊胜于无.说到这里 ...

  3. webstorm tslint配置

    webstorm设置 settings >> TypeScript >> TSLint, 勾选 Enable ,选取 tslint包路径...npm\node_modules\ ...

  4. jdk1.7和jdk1.8在接口方面的改动

    1.JDK7及其之前,接口中都是抽象方法,且不能出现static方法 2.接口的变量都是public final static 全局静态常量,无变化 3.接口中可以添加非抽象方法(static),通过 ...

  5. Git基本操作和使用

    基本命令: git config git init git clone git remote git fetch git commit git rebase git push 本地基本操作: git ...

  6. ajax发送时禁用按钮

    css /*div无法点击*/ .div-cant-click { pointer-events: none; } 发送ajax实例 $.ajax({ url:'url', type:'post', ...

  7. 如何在 Inno Setup 中执行命令行的命令

    Pascal Scripting: Exec Prototype: function Exec(const Filename, Params, WorkingDir: String; const Sh ...

  8. QFileDialog::getOpenFileName() hangs

    https://forum.qt.io/topic/49209/qfiledialog-getopenfilename-hangs-in-windows-when-using-the-native-d ...

  9. vue项目中使用bpmn-为节点添加颜色

    内容概述 本系列 “vue项目中使用bpmn-xxxx” 分为五篇,均为自己使用过程中用到的实例,手工原创,目前属于陆续更新中.主要包括vue项目中bpmn使用实例.应用技巧.基本知识点总结和需要注意 ...

  10. Scala教程之:Option-Some-None

    文章目录 Option和Some Option和None Option和模式匹配 在java 8中,为了避免NullPointerException,引入了Option,在Scala中也有同样的用法. ...