luogu P2000 拯救世界
嘟嘟嘟
题目有点坑,要你求的多少大阵指的是召唤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 拯救世界的更多相关文章
- luogu P2000 拯救世界 生成函数_麦克劳林展开_python
模板题. 将所有的多项式按等比数列求和公式将生成函数压缩,相乘后麦克劳林展开即可. Code: n=int(input()) print((n+1)*(n+2)*(n+3)*(n+4)//24)
- [题解] Luogu P2000 拯救世界
生成函数板子题...... 要写高精,还要NTT优化......异常dl 这个并不难想啊...... 一次召唤会涉及到\(10\)个因素,全部写出来,然后乘起来就得到了答案的生成函数,输出\(n\)次 ...
- 洛谷P2000 拯救世界(生成函数)
题面 题目链接 Sol 生成函数入门题 至多为\(k\)就是\(\frac{1-x^{k+1}}{1-x}\) \(k\)的倍数就是\(\frac{1}{1-x^k}\) 化简完了就只剩下一个\(\f ...
- 【洛谷】P2000 拯救世界
题解 小迪的blog : https://www.cnblogs.com/RabbitHu/p/9178645.html 请大家点推荐并在sigongzi的评论下面点支持谢谢! 掌握了小迪生成函数的有 ...
- Luogu 2000 拯救世界
从胡小兔的博客那里过来的,简单记一下生成函数. 生成函数 数列$\{1, 1, 1, 1, \cdots\}$的生成函数是$f(x) = 1 + x + x^2 + x^3 + \cdots$,根据等 ...
- [洛谷P2000 拯救世界]
生成函数版题. 考虑对于这些条件写出\(OGF\) \(1 + x^6 + x^{12} + x^{18}..... = \frac{1}{1 - x^6}\) \(1 + x + x ^ 2 + x ...
- 清北学堂模拟赛d7t6 拯救世界
分析:如果题目中没有环的话就是一道裸的最长路的题目,一旦有环每个城市就会被救多次火了.把有向有环图变成有向无环图只需要tarjan一边就可以了. #include <bits/stdc++.h& ...
- [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^ ...
- Luogu2000 拯救世界
题目链接:戳我 生成函数的入门题吧. 我们可以把条件限制转化为生成函数,然后用第i项的系数来表示一共使用n块石头的方案个数. (你问我为什么?你可以自己演算一下,或者去看大佬的博客-->这里面讲 ...
随机推荐
- /proc文件系统(二):/proc/<pid>/stat
0. 前言 /proc 文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间. 它以文件系统的方式为内核与进程提供通信的接口.用户和应用程序可以通过/proc得到系统的信息,并可以改变内核的某 ...
- Visual Studio 2015 激活码
专业版:HMGNV-WCYXV-X7G9W-YCX63-B98R2 企业版:HM6NR-QXX7C-DFW2Y-8B82K-WTYJV
- 【手记】解决涉及office的程序报“Unable to cast COM object of type System._ComObject...”的问题
报错内容大概像这种: 如果该电脑曾经装过WPS,那解决方法就是把WPS装回来,可以不用,但别卸,把它供着,惹不起.
- VS2012使用验证控件出现[ASP.NET]WebForms UnobtrusiveValidationMode 需要 'jquery' 的 ScriptResourceMapping。請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)。的解决办法。
方法一:在webconfig中找到 <appSettings><add key="aspnet:UseTaskFriendlySynchronizationContext& ...
- MySQL中表名重命名
第一种办法:##修改表名, TO 或AS都可以,也以省略掉 ## ALTER TABLE 表名 RENAME [TO|AS] 新表名 ALTER TABLE user10 RENAME TO user ...
- Spring的IOC/DI使用到的技术
一.了解Spring IOC/DI 1:Spring有两大核心技术,控制反转(Inversion of Control, IOC)/依赖注入(Dependency Injection,DI)和面向切面 ...
- webpack打包时排除其中一个css、js文件,或单独打包一个css、js文件
在项目中经常会需要将一些接口的配合文件或者某些样式文件,分离出来单独打包,便于后期改动,这里我以css文件为例,介绍实现两种方法: 项目目录: 如上图所示,现在我需要将项目中的scBtn.css文件单 ...
- 2017-12-02 编程语言试验之Antlr4+JavaScript实现"圈4"
参考: ANTLR4: Making a compiler with the JavaScript runtime 演示效果虽弱, 还是先上图吧: 在线演示: 地址. 源码库: program-in- ...
- git命令详解(一)
今天我们来详解一下git的各种命令,此为git的第一篇,后续还会有好几篇,希望大家看了能有所进步 第一篇的命令 1.git commit 2.git branch 3.git merge 4.git ...
- Visual Flow 简介
Visual Flow(流) Salesforce提供了几种自动化流程工具,其中的Visual Flow(流)可以用来实现用户界面和逻辑,并对数据进行CRUD(Create 创建,Read 读取,Up ...