SWUST OJ 2540 少女输出问题
来源:互联网 发布:显卡超频软件 编辑:程序博客网 时间:2024/04/27 15:31
题目链接:见这里
题意: 中文题目, FFT裸题。
代码如下:
////Created by BLUEBUFF 2016/1/11//Copyright (c) 2016 BLUEBUFF.All Rights Reserved//#pragma comment(linker,"/STACK:102400000,102400000")//#include <ext/pb_ds/assoc_container.hpp>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/hash_policy.hpp>//#include <bits/stdc++.h>#include <set>#include <map>#include <queue>#include <stack>#include <cmath>#include <cstdio>#include <time.h>#include <cstdlib>#include <cstring>#include <complex>#include <sstream> //isstringstream#include <iostream>#include <algorithm>using namespace std;//using namespace __gnu_pbds;typedef long long LL;typedef unsigned long long uLL;typedef pair<int, LL> pp;#define REP1(i, a, b) for(int i = a; i < b; i++)#define REP2(i, a, b) for(int i = a; i <= b; i++)#define REP3(i, a, b) for(int i = a; i >= b; i--)#define CLR(a, b) memset(a, b, sizeof(a))#define MP(x, y) make_pair(x,y)template <class T1, class T2>inline void getmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void getmin(T1 &a, T2 b) { if (b<a)a = b; }const int maxn = 270010;const int maxm = 1e5+5;const int maxs = 10;const int maxp = 1e3 + 10;const int INF = 1e9;const int UNF = -1e9;const int mod = 1e9 + 7;const int rev = (mod + 1) >> 1; // FWTconst double PI = acos(-1);//headstruct FastIO{ static const int S = 1310720; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int xchar() { static char buf[S]; static int len = 0, pos = 0; if (pos == len) pos = 0, len = fread(buf, 1, S, stdin); if (pos == len) return -1; return buf[pos ++]; } inline int xuint() { int c = xchar(), x = 0; while (c <= 32) c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x; } inline int xint() { int s = 1, c = xchar(), x = 0; while (c <= 32) c = xchar(); if (c == '-') s = -1, c = xchar(); for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0'; return x * s; } inline void xstring(char *s) { int c = xchar(); while (c <= 32) c = xchar(); for (; c > 32; c = xchar()) * s++ = c; *s = 0; } inline void wchar(int x) { if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0; wbuf[wpos ++] = x; } inline void wint(LL x) { if (x < 0) wchar('-'), x = -x; char s[24]; int n = 0; while (x || !n) s[n ++] = '0' + x % 10, x /= 10; while (n--) wchar(s[n]); } inline void wstring(const char *s) { while (*s) wchar(*s++); } ~FastIO() { if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0; }} io;typedef complex <double> Complex;void rader(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;} if(j < k) j += k; }}void fft(Complex *y, int len, int op) { rader(y, len); for(int h = 2; h <= len; h <<= 1) { double ang = op * 2 * PI / h; Complex wn(cos(ang), sin(ang)); for(int j = 0; j < len; j += h) { Complex w(1, 0); for(int k = j; k < j + h / 2; k++) { Complex u = y[k]; Complex t = w * y[k + h / 2]; y[k] = u + t; y[k + h / 2] = u - t; w = w * wn; } } } if(op == -1) for(int i = 0; i < len; i++) y[i] /= len;}int n, m, x;Complex x1[maxn], x2[maxn];int main(){ //scanf("%d%d", &n, &m); n = io.xint(); m = io.xint();// REP1(i, 0, n) a[i] = io.xint();// REP1(i, 0, m) b[i] = io.xint(); int len = 1; while(len < n * 2 || len < m * 2) len <<= 1; REP1(i, 0, n){ x = io.xint(); x1[i] = Complex(x, 0); } REP1(i, n, len) x1[i] = Complex(0, 0); REP1(i, 0, m){ x = io.xint(); x2[i] = Complex(x, 0); } REP1(i, m, len) x2[i] = Complex(0, 0); fft(x1, len, 1); fft(x2, len, 1); REP1(i, 0, len) x1[i] = x1[i] * x2[i]; fft(x1, len, -1); len = n + m - 1; for(int i = 0; i < len - 1; i++) printf("%d ", (int) (x1[i].real() + 0.5)); printf("%d\n", (int) (x1[len - 1].real() + 0.5)); return 0;}
0 0
- SWUST OJ 2540 少女输出问题
- SWUST OJ数据结构输出格式
- swust oj 0963 背包问题
- 代码:swust oj 0083 阶乘问题
- SWUST oj 2478 最短路问题
- SWUST OJ 1768 n皇后问题
- 最近点对问题 Swust Oj 794
- swust OJ 1400 8数码问题
- Swust Oj 数据结构题目输出格式总结(持续更新)
- SWUST OJ 1025
- SWUST OJ 1137 STICKS
- SWUST OJ 1804 二进制
- swust OJ 1515
- swust OJ 1619 中位数
- SWUST OJ 2285
- swust.oj 0259
- swust.oj 0964
- swust.oj,0541
- GridBagLayout布局管理器
- Unity 使用Vector.Cross()判定方位
- java泛型
- 解决首次启动程序白屏时间过长的问题
- 有道词典 Chrome取词插件
- SWUST OJ 2540 少女输出问题
- RESTful api接口规范
- C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉
- Android手机利用加速度统计跌落次数
- 移动端自由移动元素位置
- 密码等级:至少包含字母、大小写数字、字符中的两种 JS实现方案
- manipulate array of data in SQL
- angularJS2.0入门 命令行/npm下载安装
- git push 出现 you are not allowed to upload merges 错误提示