嘟嘟嘟




题目有点坑,要你求的多少大阵指的是召唤kkk的大阵数 * lzn的大阵数,不是相加。




看到这个限制条件,显然要用生成函数推一推。

比如第一个条件“金神石的块数必须是6的倍数”,就是\(1 +x ^ 6 + x ^ {12} + \ldots\),也就是\(\frac{1 - x ^ {6n}}{1 - x ^ 6}\)。当\(x \in (-1, 1)\)时,就变成了\(\frac{1}{1 - x ^ 6}\)。

剩下的同理。

然后把这10个条件都乘起来,一顿化简,答案就是\(\frac{(n + 1) * (n + 2) * (n + 3) *(n + 4)}{24}\)。




本来想快乐的写高精,但是\(n = 1e5\)还非得用fft。

于是就写了一发,不开O2会TLE飞,开了后TLE最后一个点。然后把fft的预处理改成bin哥的写法后就过了。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const db PI = acos(-1);
const int maxn = 4e6 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} char a1[maxn];
int n, m, a[maxn], b[maxn]; int len = 1;
struct Comp
{
db x, y;
In Comp operator + (const Comp& oth)const
{
return (Comp){x + oth.x, y + oth.y};
}
In Comp operator - (const Comp& oth)const
{
return (Comp){x - oth.x, y - oth.y};
}
In Comp operator * (const Comp& oth)const
{
return (Comp){x * oth.x - y * oth.y, x * oth.y + y * oth.x};
}
friend In void swap(Comp& a, Comp& b)
{
swap(a.x, b.x); swap(a.y, b.y);
}
}c[maxn], d[maxn], omg[maxn], inv[maxn];
int r[maxn];
In void init()
{
omg[0] = inv[0] = (Comp){1, 0};
omg[1] = inv[len - 1] = (Comp){cos(2 * PI / len), sin(2 * PI / len)};
for(int i = 2; i < len; ++i) omg[i] = inv[len - i] = omg[i - 1] * omg[1];
}
In void fft(Comp* a, Comp* omg)
{
for(int i = 0; i < len; ++i) if(i < r[i]) swap(a[i], a[r[i]]);
for(int l = 2; l <= len; l <<= 1)
{
int q = l >> 1;
for(Comp* p = a; p != a + len; p += l)
for(int i = 0; i < q; ++i)
{
Comp tp = omg[len / l * i] * p[i + q];
p[i + q] = p[i] - tp, p[i] = p[i] + tp;
}
}
} In void mul(int* a, int* b)
{
int tot = max(n, m); len = 1;
while(len < (tot << 1)) len <<= 1;
int lim = 0;
while((1 << lim) < len) ++lim;
for(int i = 0; i < len; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (lim - 1));
for(int i = 0; i < len; ++i) c[i] = d[i] = (Comp){0, 0};
for(int i = 0; i < n; ++i) c[i] = (Comp){a[i], 0};
for(int i = 0; i < m; ++i) d[i] = (Comp){b[i], 0};
init();
fft(c, omg), fft(d, omg);
for(int i = 0; i < len; ++i) c[i] = c[i] * d[i];
fft(c, inv);
for(int i = 0; i <= len; ++i) a[i] = 0;
for(int i = 0; i < len; ++i)
{
a[i] += (int)(c[i].x / len + 0.5);
if(a[i] >= 10) a[i + 1] += a[i] / 10, a[i] %= 10;
}
n = len;
while(n - 1 && !a[n - 1]) --n;
// for(int i = n - 1; i >= 0; --i) printf("%d", a[i]); enter;
}
In void add(int* a, int x, int& n)
{
a[0] += x;
for(int i = 0; i < n; ++i)
if(a[i] >= 10) a[i + 1] += a[i] / 10, a[i] %= 10;
else break;
++n;
while(n - 1 && !a[n - 1]) --n;
// for(int i = n - 1; i >= 0; --i) printf("%d", a[i]); enter;
}
In void div(int* a, int x)
{
static int ret[maxn];
reverse(a, a + n);
int tp = 0, cnt = 0;
for(int i = 0; i < n; ++i)
{
tp = tp * 10 + a[i];
ret[++cnt] = tp / x;
tp %= x;
}
int sta = 1;
while(sta < cnt && !ret[sta]) ++sta;
for(int i = sta; i <= cnt; ++i) write(ret[i]); enter;
} int main()
{
// freopen("random.in", "r", stdin);
// freopen("ac.out", "w", stdout);
scanf("%s", a1);
m = n = strlen(a1);
for(int i = 0; i < n; ++i) b[i] = a[i] = a1[n - i - 1] - '0';
add(a, 1, n); add(b, 1, m);
for(int i = 2; i <= 4; ++i)
{
add(b, 1, m);
mul(a, b);
}
div(a, 24);
return 0;
}

luogu P2000 拯救世界的更多相关文章

  1. luogu P2000 拯救世界 生成函数_麦克劳林展开_python

    模板题. 将所有的多项式按等比数列求和公式将生成函数压缩,相乘后麦克劳林展开即可. Code: n=int(input()) print((n+1)*(n+2)*(n+3)*(n+4)//24)

  2. [题解] Luogu P2000 拯救世界

    生成函数板子题...... 要写高精,还要NTT优化......异常dl 这个并不难想啊...... 一次召唤会涉及到\(10\)个因素,全部写出来,然后乘起来就得到了答案的生成函数,输出\(n\)次 ...

  3. 洛谷P2000 拯救世界(生成函数)

    题面 题目链接 Sol 生成函数入门题 至多为\(k\)就是\(\frac{1-x^{k+1}}{1-x}\) \(k\)的倍数就是\(\frac{1}{1-x^k}\) 化简完了就只剩下一个\(\f ...

  4. 【洛谷】P2000 拯救世界

    题解 小迪的blog : https://www.cnblogs.com/RabbitHu/p/9178645.html 请大家点推荐并在sigongzi的评论下面点支持谢谢! 掌握了小迪生成函数的有 ...

  5. Luogu 2000 拯救世界

    从胡小兔的博客那里过来的,简单记一下生成函数. 生成函数 数列$\{1, 1, 1, 1, \cdots\}$的生成函数是$f(x) = 1 + x + x^2 + x^3 + \cdots$,根据等 ...

  6. [洛谷P2000 拯救世界]

    生成函数版题. 考虑对于这些条件写出\(OGF\) \(1 + x^6 + x^{12} + x^{18}..... = \frac{1}{1 - x^6}\) \(1 + x + x ^ 2 + x ...

  7. 清北学堂模拟赛d7t6 拯救世界

    分析:如果题目中没有环的话就是一道裸的最长路的题目,一旦有环每个城市就会被救多次火了.把有向有环图变成有向无环图只需要tarjan一边就可以了. #include <bits/stdc++.h& ...

  8. [LGP2000] 拯救世界

    6的倍数 1/(1-x^6) 最多9块 (1-x^10)/(1-x) 最多5块 (1-x^6)/(1-x) 4的倍数 1/(1-x^4) 最多7块 (1-x^8)/(1-x) 2的倍数 1/(1-x^ ...

  9. Luogu2000 拯救世界

    题目链接:戳我 生成函数的入门题吧. 我们可以把条件限制转化为生成函数,然后用第i项的系数来表示一共使用n块石头的方案个数. (你问我为什么?你可以自己演算一下,或者去看大佬的博客-->这里面讲 ...

随机推荐

  1. MySQL中MyISAM和InnoDB两种主流存储引擎的特点

    一.数据库引擎(Engines)的概念 MySQ5.6L的架构图: MySQL的存储引擎全称为(Pluggable Storage Engines)插件式存储引擎.MySQL的所有逻辑概念,包括SQL ...

  2. SpringMVC+jquery.uploadify 上传文件

    前言 以前用Asp.net MVC+uploadify上传文件,最近学习SpringMVC,所以就用SpringMVC+uploadify做个上传文件的demo. 刚开始用form表单的方式提交,在C ...

  3. IdentityServer4 中文文档 -6- (简介)示例服务器和测试

    IdentityServer4 中文文档 -6- (简介)示例服务器和测试 原文:http://docs.identityserver.io/en/release/intro/test.html 目 ...

  4. C#基础 数据类型 类型转换

    本节主要讲解数据类型和各类型之间的转换,两点都是重点,难点在于各种转换的活学活用. 一   数据类型 (一)基本数据类型 1  值类型 (1)整形         int                ...

  5. IdentityServer4-客户端定义-翻译

    客户端定义(Defining Client) 客户端可以从你的IDS服务器请求tokens. 通常,客户端需要遵循下面的通用设置: 一个唯一的Client ID 如果需要还可以提供密码 允许与toke ...

  6. MEF 插件式开发之 DotNetCore 中强大的 DI

    背景叙述 在前面几篇 MEF 插件式开发 系列博客中,我分别在 DotNet Framework 和 DotNet Core 两种框架下实验了 MEF 的简单实验,由于 DotNet Framewor ...

  7. Windows下使用Rtools编译R语言包

    使用devtools安装github中的R源代码时,经常会出各种错误,索性搜了一下怎么在Windows下直接打包,网上的资料也是参差不齐,以下是自己验证通过的. 一.下载Rtools 下载地址:htt ...

  8. loadrunner 脚本开发-定义全局变量

    脚本开发-定义全局变量 by:授客 QQ:1033553122 如果参数是全局的,在脚本中的任何一个Action中都可以使用,变量一般是局部的,如果跨Action调用会出现未声明的错误. 打开Scri ...

  9. JVM、Gc工作机制详解

    JVM主要包括四个部分: 类加载器(ClassLoad) 执行引擎 内存区: 本地方法接口:类似于jni调本地native方法 内存区包括四个部分: 1.方法区:包含了静态变量.常量池.构造函数等 2 ...

  10. Expo大作战(三十八)--expo sdk api之 FileSystem(文件操作系统)

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...