【FFT】 HDOJ 1402 A * B Problem Plus

FFT模板题。。。本渣是向kuangbin大大学习的。。。本渣的程序跑的很慢。。。那些快的是不是用NTT实现的。。。。

#include <iostream>
#include <queue> 
#include <stack> 
#include <map> 
#include <set> 
#include <bitset> 
#include <cstdio> 
#include <algorithm> 
#include <cstring> 
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 900005
#define maxm 1000005
#define eps 1e-10
#define mod 1000000007
#define INF 999999999
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid 
#define rson o<<1 | 1, mid+1, R
#pragma comment(linker, "/STACK:16777216")
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}
LL gcd(LL _a, LL _b){if(!_b) return _a;else return gcd(_b, _a%_b);}
// head

struct complex
{
	double r, i;
	complex(double r = 0, double i = 0) : r(r), i(i) {}
	complex operator + (const complex b) const {
		return complex(r + b.r, i + b.i);
	}
	complex operator - (const complex b) const {
		return complex(r - b.r, i - b.i);
	}
	complex operator * (const complex b) const {
		return complex(r * b.r - i * b.i, r * b.i + i * b.r);
	}
}x1[maxn], x2[maxn];

int sum[maxn];
char s1[maxn], s2[maxn];

void chang(complex y[], int len)
{
	for(int i = 1, j = len / 2; i < len-1; i++) {
		if(i < j) swap(y[i], y[j]);
		int k = len / 2;
		while(j >= k) {
			j -= k;
			k /= 2;
		}
		j += k;
	}
}

void fft(complex y[], int len, int on)
{
	chang(y, len);
	for(int i = 2; i <= len; i <<= 1) {
		complex wn(cos(-on * 2 * PI / i), sin(-on * 2 * PI / i));
		for(int j = 0; j < len; j += i) {
			complex w(1.0, 0.0);
			for(int k = j; k < j + i / 2; k++) {
				complex u = y[k];
				complex t = w * y[k + i / 2];
				y[k] = u + t;
				y[k + i / 2] = u - t;
				w = w * wn;
			}
		}
	}
	if(on == -1) for(int i = 0; i < len; i++) y[i].r /= len;
}

void work(void)
{
	int len1 = strlen(s1);
	int len2 = strlen(s2);
	int len = 1;
	while(len < 2 * len1 || len < 2 * len2) len <<= 1;
	for(int i = 0; i < len1; i++) x1[i] = complex(s1[len1-1-i] - '0', 0.0);
	for(int i = 0; i < len2; i++) x2[i] = complex(s2[len2-1-i] - '0', 0.0);
	for(int i = len1; i < len; i++) x1[i] = complex(0.0, 0.0);
	for(int i = len2; i < len; i++) x2[i] = complex(0.0, 0.0);
	fft(x1, len, 1);
	fft(x2, len, 1);
	for(int i = 0; i < len; i++) x1[i] = x1[i] * x2[i];
	fft(x1, len, -1);
	sum[len] = 0;
	for(int i = 0; i < len; i++) sum[i] = x1[i].r + 0.5;	
	for(int i = 0; i < len; i++) sum[i+1] += sum[i] / 10, sum[i] %= 10;
	while(!sum[len] && len) len--;
	for(int i = len; i >= 0; i--) printf("%d", sum[i]);
	printf("\n");

}

int main(void)
{
	while(scanf("%s%s", s1, s2)!=EOF) {
		work();
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的记忆游戏(附源代码)   项目:JavaScript 记忆游戏(附源代码) 记忆检查游戏是一个使用 HTML5、CSS 和 JavaScript 开发的简单项目。这个游戏是关于测试你的短期 记忆技能。玩这个游戏 时,一系列图像会出现在一个盒子形状的区域中 。玩家必须找到两个相同的图像并单击它们以使它们消失。 如何运行游戏? 记忆游戏项目仅包含 HTML、CSS 和 JavaScript。谈到此游戏的功能,用户必须单击两个相同的图像才能使它们消失。 点击卡片或按下键盘键,通过 2 乘 2 旋转来重建鸟儿对,并发现隐藏在下面的图像! 如果翻开的牌面相同(一对),您就赢了,并且该对牌将从游戏中消失! 否则,卡片会自动翻面朝下,您需要重新尝试! 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,通过单击 memorygame-index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值