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块石头的方案个数. (你问我为什么?你可以自己演算一下,或者去看大佬的博客-->这里面讲 ...
随机推荐
- Java提高篇之理解java的三大特性——继承
在<Think in java>中有这样一句话:复用代码是Java众多引人注目的功能之一.但要想成为极具革命性的语言,仅仅能够复制代码并对加以改变是不够的,它还必须能够做更多的事情.在这句 ...
- mybatis教程之原理剖析
MyBatis是目前非常流行的ORM框架,功能很强大,然而其实现却比较简单.优雅.本文通过代理的方式来看下其实现 方式一:传统API方式 @Test public void add() throws ...
- 使用Asp.Net Core MVC 开发项目实践[第五篇:缓存的使用]
项目中我们常常会碰到一些数据,需要高频率用到但是又不会频繁变动的这类,我们就可以使用缓存把这些数据缓存起来(比如说本项目的导航数据,帖子频道数据). 我们项目中常用到有Asp.Net Core 本身提 ...
- Python 判断文件/目录是否存在
使用 os 模块 判断文件是否存在 os.path.isfile(path) 判断目录是否存在 os.path.isdir(path) 判断路径是否存在 # 使用 path 模块 os.path.ex ...
- 一个比较好用的省内存的ORM
http://www.52chloe.com 记录一下,完了,就这样
- 玩转物联网之MQTT
物联网概述 物联网——即Internet-of-Things,其实这个概念由来已久,简单来讲,物联网是物与物.人与物之间的信息传递与控制简称.它和能源.电子信息.医疗.交通.零售.物流.工业制造等行业 ...
- jQuery 小特效【文本框折叠隐藏,展开显示】【下拉菜单】【颜色渐变】【弹窗+遮罩】
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- Docker-compose 编排工具安装
介绍 Compose 是一个定义和管理多容器的工具,使用Python语言编写,使用Compose配置文件描述多个容器应用的架构, 比如什么镜像,数据卷,网络,映射端口等:然后一条命令管理所有服务,比如 ...
- Spider-one
1. 爬虫是如何采集网页数据的: 网页的三大特征: -1. 每个网页都有自己的 URL(统一资源定位符)地址来进行网络定位. -2. 每个网页都使用 HTML(超文本标记语言)来描述页面信息. -3. ...
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...