感觉...昨天是真的傻...

题意

T个询问,每个询问给一个n,求

$ \frac{\sum_{n}^{i = 1}Fib_{i} * i}{n * (n + 1) / 2} $

Fib是斐波那契数列,对998244353取模

然后...我昨天把n乘了之后就忘记取模了...

30分做法

设$ a_{i} = i * Fib_{i} $, 有$ a_{i} = a_{i - 1} + a_{i - 2} + Fib_{i - 1} + Fib_{i - 2} $,然后就写了一个5*5的转移矩阵,感觉很稳……

长这样:

\begin{bmatrix}
Fib_{i} & Fib{i - 1} & a_{i} & a_{i - 1} & sum_{i - 1}
\end{bmatrix}

转移矩阵长这样:

\begin{bmatrix}
1 & 1 & 1 & 0 & 0 \\
1 & 0 & 2 & 0 & 0\\
0 & 0 & 1 & 1 & 1\\
0 & 0 & 1 & 0 & 0\\
0 & 0 & 0 & 0 & 1
\end{bmatrix}

虽然这个东西也过了几万组对拍,但是我喜闻乐见地把std也顺便写挂了(捂脸),所以这两个东西都只有10分...

Code:

#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll; const ll mod = ; int testCase;
ll n; struct Matrix {
ll l1, l2, s[][]; inline void init() {
l1 = l2 = ;
memset(s, , sizeof(s));
} friend Matrix operator * (const Matrix a, const Matrix b) {
Matrix res;
res.init();
res.l1 = a.l1, res.l2 = b.l2;
for(int i = ; i < a.l1; i++)
for(int j = ; j < b.l2; j++)
for(int k = ; k < a.l2; k++)
res.s[i][j] = (res.s[i][j] + a.s[i][k] * b.s[k][j] % mod) % mod;
return res;
} inline Matrix pow(Matrix a, ll b) {
Matrix res = *this;
for(; b > ; b >>= ) {
if(b & ) res = res * a;
a = a * a;
}
return res;
} inline void print() {
for(int i = ; i < l1; i++, printf("\n"))
for(int j = ; j < l2; j++)
printf("%lld ", s[i][j]);
} } f; inline ll pow(ll x, ll y) {
ll res = ;
for(x %= mod; y > ; y >>= ) {
if(y & ) res = res * x % mod;
x = x * x % mod;
}
return res;
} inline ll solve() {
if(n == ) return 1LL;
if(n == ) return 3LL; Matrix g;
g.init();
g.l1 = , g.l2 = ;
g.s[][] = g.s[][] = g.s[][] = ;
g.s[][] = ;
g.s[][] = ;
// g.print(); g = g.pow(f, n - ); // g.print(); return g.s[][];
} int main() {
f.init();
f.l1 = f.l2 = ;
f.s[][] = f.s[][] = f.s[][] = ;
f.s[][] = f.s[][] = f.s[][] = f.s[][] = ;
f.s[][] = f.s[][] = ;//f.s[4][2] = 1;
f.s[][] = ; // f.print(); for(scanf("%d", &testCase); testCase--; ) {
scanf("%lld", &n);
ll tmp = n * (n + ) / ;
ll inv = pow(tmp, mod - );
ll sum = solve();
printf("%lld\n", inv * sum % mod);
}
return ;
}

100分做法  

找规律题惹不起a...

$sum_{n} = n * Fib_{n + 2} - Fib_{n + 3} + 2$

所以就变成一个斐波那契了
并不能推导出来...

Code:

#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll; const ll mod = ; int testCase;
ll n; struct Matrix {
ll s[][]; inline void init() {
memset(s, , sizeof(s));
} friend Matrix operator * (const Matrix a, const Matrix b) {
Matrix res;
res.init();
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
for(int k = ; k <= ; k++)
res.s[i][j] = (res.s[i][j] + a.s[i][k] * b.s[k][j] % mod) % mod;
return res;
} inline Matrix pow(ll b) {
Matrix res, a = *this;
res.init();
for(int i = ; i <= ; i++) res.s[i][i] = ;
for(; b > ; b >>= ) {
if(b & ) res = res * a;
a = a * a;
}
return res;
} } f; inline ll pow(ll a, ll b) {
ll res = ;
for(; b > ; b >>= ) {
if(b & ) res = res * a % mod;
a = a * a % mod;
}
return res;
} inline ll solve() {
Matrix res = f.pow(n + );
return (res.s[][] * n % mod - res.s[][] + + mod) % mod;
} int main() {
f.init();
f.s[][] = f.s[][] = f.s[][] = ;
for(scanf("%d", &testCase); testCase--; ) {
scanf("%lld", &n);
ll inv = pow((n * (n + ) / )% mod, mod - );
ll sum = solve();
// printf("%lld %lld\n", sum, inv);
printf("%lld\n", sum * inv % mod);
}
return ;
}

感觉还挺有趣的……

Luogu U15118 萨塔尼亚的期末考试(fail)的更多相关文章

  1. 萨塔尼亚的期末考试(fail)

    题解: 这题比较妙啊... 首先暴力自己算是找不出规律的 有一种直觉就是可以把式子变成{f[1]+...f[n]}+{f[2]+...+f[n]}+{f[3]+...+f[n]}... 然后看了题解发 ...

  2. [luogu_U15118]萨塔尼亚的期末考试

    https://zybuluo.com/ysner/note/1239615 题面 \(T\)次询问,求出\[\sum_{i=1}^n\frac{i}{\frac{n(n+1)}{2}}fib_i\] ...

  3. [luogu] P3745 [六省联考2017]期末考试 (贪心)

    P3745 [六省联考2017]期末考试 题目描述 有 \(n\) 位同学,每位同学都参加了全部的 \(m\) 门课程的期末考试,都在焦急的等待成绩的公布. 第 \(i\) 位同学希望在第 \(t_i ...

  4. Vigenère Cipher 维吉尼亚加解密算法

    维吉尼亚的加解密有两种方法. 第一种是查表:第一行为明文,第一列为密钥,剩余的为对应的密文 第二种方法是转化计算法:逐个将字符转化为从零开始的数字,对数字进行加密/解密后,再转化为字符. 本文要用c+ ...

  5. [加密]C#实现维吉尼亚加密与解密(解密前提为已知密匙)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. 随机练习:C#实现维吉尼亚加密与解密(解密前提为已知密匙)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. 维吉尼亚密码-攻防世界(shanghai)

    维吉尼亚密码 维吉尼亚密码是使用一系列 凯撒密码 组成密码字母表的加密算法,属于多表密码的一种简单形式. 加密原理 维吉尼亚密码的前身,是我们熟悉的凯撒密码. 凯撒密码的加密方式是依靠一张字母表中的每 ...

  8. [CTF]维吉尼亚密码(维基利亚密码)

    [CTF]维吉尼亚密码(维基利亚密码) ----------------------百度百科 https://baike.baidu.com/item/维吉尼亚密码/4905472?fr=aladdi ...

  9. 【Luogu】P3745期末考试(三分)

    题目链接 我是怎么把“期末考试”在本地写成“假期计划”的 qwq???? 本题把学生和卷子都排个序,按出成绩最晚时间三分. 三分之后可以O(n)的时间统计答案,因为修改卷子出成绩的时间可以贪心计划. ...

随机推荐

  1. 201621123014《Java程序设计》第十三周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以被多个用户通过网 ...

  2. BEC listen and translation exercise 11

    When you are in any contest you should work as if there were — to the very last minute — a chance to ...

  3. UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...

  4. Technocup 2019 C. Compress String

    一个字符串 $s$,你要把它分成若干段,有两种合法的段 1.段长为 $1$,代价为 $a$ 2.这个段是前面所有段拼起来组成的字符串的字串,代价为 $b$ 问最小代价 $|s| \leq 5000$ ...

  5. Yii错误404页面

    'errorHandler'=>array( // use 'site/error' action to display errors 'errorAction'=>YII_DEBUG ? ...

  6. C#:使用UPnP来穿透NAT使内网接口对外网可见

    在写完Object 672后,软件的一个致命问题暴露出来,如果服务器和客户端都在内网环境下,即双方都通过NAT来接触外网,那么此时客户端是无法直接和服务器交流的. 解决方案可以是: 1:把服务器部署在 ...

  7. BZOJ3489:A simple rmq problem

    浅谈\(K-D\) \(Tree\):https://www.cnblogs.com/AKMer/p/10387266.html 题目传送门:https://lydsy.com/JudgeOnline ...

  8. 转载:trap 的用法 /etc/init.d/rcS trap :1 2 3 24

    在有些情况下,我们不希望自己的shell脚本在运行时刻被中断,比如说我们写得shell脚 本设为某一用户的默认shell,使这一用户进入系统后只能作某一项工作,如数据库备份, 我 们可不希望用户使用c ...

  9. 转载:MongoDB 在 58 同城百亿量级数据下的应用实践

    为什么要使用 MongoDB? MongoDB 这个来源英文单词“humongous”,homongous 这个单词的意思是“巨大的”.“奇大无比的”,从 MongoDB 单词本身可以看出它的目标是提 ...

  10. jenkins学习 03 jenkins配置Maven项目

    我们的产品使用Git作为版本管理工具,而jenkins需要git插件来支持git,所以我们需要为jenkins添加git插件. 在Available tab页中找到Git Plugin 点击下方的In ...