题意:有四种花色的牌,每种花色的牌中只能使用数值的约数个数大于2的牌.现在遗失了c张牌.每种花色选一张,求值在区间[a,b]的每个数值的选择方法有多少.

分析:约数个数大于2,即合数.所以先预处理出50000内的所有素数.

然后根据给出的c个遗失牌和素数与否.构造生成多项式,因为上限是b,所以每个多项式只需构造b项即可.4类牌对应4个多项式,求三次卷积求出答案.

坑点:复数类里要用long double

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = 4e5 + 10;
  5. const long double PI = acos(-1.0);
  6. struct Complex{
  7. long double x, y;
  8. inline Complex operator+(const Complex b) const {
  9. return (Complex){x +b.x,y + b.y};
  10. }
  11. inline Complex operator-(const Complex b) const {
  12. return (Complex){x -b.x,y - b.y};
  13. }
  14. inline Complex operator*(const Complex b) const {
  15. return (Complex){x *b.x -y * b.y,x * b.y + y * b.x};
  16. }
  17. } va[MAXN * 2 + MAXN / 2], vb[MAXN * 2 + MAXN / 2];
  18. int lenth = 1, rev[MAXN * 2 + MAXN / 2];
  19. int N, M; // f 和 g 的数量
  20. //f g和 的系数
  21. // 卷积结果
  22. // 大数乘积
  23. int f[MAXN],g[MAXN];
  24. vector<LL> conv;
  25. vector<LL> multi;
  26. //f g
  27. void init()
  28. {
  29. int tim = 0;
  30. lenth = 1;
  31. conv.clear(), multi.clear();
  32. memset(va, 0, sizeof va);
  33. memset(vb, 0, sizeof vb);
  34. while (lenth <= N + M - 2)
  35. lenth <<= 1, tim++;
  36. for (int i = 0; i < lenth; i++)
  37. rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (tim - 1));
  38. }
  39. void FFT(Complex *A, const int fla)
  40. {
  41. for (int i = 0; i < lenth; i++){
  42. if (i < rev[i]){
  43. swap(A[i], A[rev[i]]);
  44. }
  45. }
  46. for (int i = 1; i < lenth; i <<= 1){
  47. const Complex w = (Complex){cos(PI / i), fla * sin(PI / i)};
  48. for (int j = 0; j < lenth; j += (i << 1)){
  49. Complex K = (Complex){1, 0};
  50. for (int k = 0; k < i; k++, K = K * w){
  51. const Complex x = A[j + k], y = K * A[j + k + i];
  52. A[j + k] = x + y;
  53. A[j + k + i] = x - y;
  54. }
  55. }
  56. }
  57. }
  58. void getConv(){ //求多项式
  59. init();
  60. for (int i = 0; i < N; i++)
  61. va[i].x = f[i];
  62. for (int i = 0; i < M; i++)
  63. vb[i].x = g[i];
  64. FFT(va, 1), FFT(vb, 1);
  65. for (int i = 0; i < lenth; i++)
  66. va[i] = va[i] * vb[i];
  67. FFT(va, -1);
  68. for (int i = 0; i <= N + M - 2; i++)
  69. conv.push_back((LL)(va[i].x / lenth + 0.5));
  70. }
  71. void getMulti() //求A*B
  72. {
  73. getConv();
  74. multi = conv;
  75. reverse(multi.begin(), multi.end());
  76. multi.push_back(0);
  77. int sz = multi.size();
  78. for (int i = 0; i < sz - 1; i++){
  79. multi[i + 1] += multi[i] / 10;
  80. multi[i] %= 10;
  81. }
  82. while (!multi.back() && multi.size() > 1)
  83. multi.pop_back();
  84. reverse(multi.begin(), multi.end());
  85. }
  86. const int up = 500005;
  87. bool check[up];
  88. int cnt[up];
  89. void pre()
  90. {
  91. for(int i=2;i<up;++i){
  92. if(check[i]) continue;
  93. for(int j=2*i;j<up;j+=i){
  94. check[j] = true;
  95. }
  96. }
  97. }
  98. bool lack[4][up];
  99. char str[100];
  100. int main()
  101. {
  102. pre();
  103. int a,b,c;
  104. while(scanf("%d %d %d",&a, &b, &c)==3){
  105. if(!a && !b && !c) continue;
  106. memset(lack,0,sizeof(lack));
  107. for(int i=1;i<=c;++i){
  108. int tmp = 0; scanf("%d",&tmp);
  109. char c; scanf("%c",&c);
  110. if(c=='S') lack[0][tmp] = true;
  111. else if(c=='H') lack[1][tmp] = true;
  112. else if(c=='C') lack[2][tmp] = true;
  113. else lack[3][tmp] = true;
  114. }
  115. N = b;
  116. for(int i=0;i<b;++i){
  117. if(check[i] && !lack[0][i]) f[i] = 1;
  118. else f[i] =0;
  119. }
  120. for(int i=1;i<4;++i){
  121. if(i>1){
  122. N = conv.size();
  123. for(int j=0;j<N;++j){
  124. f[j] = conv[j];
  125. }
  126. }
  127. M = b;
  128. for(int j=1;j<b;++j){
  129. if(check[j] && !lack[i][j]) g[j] = 1;
  130. else g[j] = 0;
  131. }
  132. getConv();
  133. }
  134. for(int i=a;i<=b;++i){
  135. printf("%lld\n",conv[i]);
  136. }
  137. puts("");
  138. }
  139. return 0;
  140. }

UVA - 12298 Super Poker II (FFT+母函数)的更多相关文章

  1. UVA 12298 Super Poker II (FFT)

    #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using ...

  2. UVA - 12298 Super Poker II NTT

    UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...

  3. UVa12298 Super Poker II(母函数 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...

  4. FFT(快速傅里叶变换):UVAoj 12298 - Super Poker II

    题目:就是现在有一堆扑克里面的牌有无数张, 每种合数的牌有4中不同花色各一张(0, 1都不是合数), 没有质数或者大小是0或者1的牌现在这堆牌中缺失了其中的 c 张牌, 告诉你a, b, c接下来c张 ...

  5. Super Poker II UVA - 12298 FFT_生成函数

    Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...

  6. bzoj2487: Super Poker II

    Description I have a set of super poker cards, consisting of an infinite number of cards. For each p ...

  7. UVA12298 Super Poker II

    怎么又是没人写题解的UVA好题,个人感觉应该是生成函数的大板子题了. 直接做肯定爆炸,考虑来一发优化,我们记一个多项式,其中\(i\)次项的系数就表示对于\(i\)这个数有多少种表示方式. 那么很明显 ...

  8. UVA 11426 - GCD - Extreme (II) (数论)

    UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...

  9. UVA 10869 - Brownie Points II(树阵)

    UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...

随机推荐

  1. C# 重命名文件

    在vb下,有一个方法可以对文件进行重命名,所以,我们只要引用到这种方法进行应用即可. 1.添加引用Microsoft.VisualBasic 2.添加命名空间using Microsoft.Visua ...

  2. 编程之美 最长递增子序列 LIS

    1. O(N*logN) 解法 先对序列排序, 然后寻找两个序列的最长公共子序列 2. O(N*N) 的动态规划解法 令 LIST[i] 表示以 i 为结尾的最长子序列的长度, 那么 LIST[J] ...

  3. ubuntu 12.04中环境变量设置

    Persistent environment variables So far we've only discussed ways set an environment variable value ...

  4. css+jq写的小小的移动端按钮的动画改变(三个很闲变成一个叉号)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 【BZOJ4443】[Scoi2015]小凸玩矩阵 二分+二分图最大匹配

    [BZOJ4443][Scoi2015]小凸玩矩阵 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个数字不能在同一行或 ...

  6. Vue基础-渲染函数-父子组件-传递数据

    Vue 测试版本:Vue.js v2.5.13 做了个 demo,把父子组件的数据都绑定到 Vue 实例 app 上,注释中的 template 相对好理解些 <div id="app ...

  7. 02.Elasticsearch入门

        Elasticsearch支持Http类型的Restful风格API请求,需要打开9200端口.Elasticsearch服务会监听两个端口9200和9300,9200提供Http Restf ...

  8. 160310、oracle数据库的读写分离

    PS:使用AbstractRoutingDataSource路由数据源实现动态数据库的调用   1. 连接哪个数据源的环境变量 package com.hysoft.common;   public  ...

  9. PHP array_merge() 函数

    <?php $a1=array("a"=>"red","b"=>"green"); $a2=array ...

  10. 几种压缩方式:zlib

    zlib:zlib.h http://www.zlib.net/manual.html 编译时加 -lz ZEXTERN int ZEXPORT compress OF((Bytef *dest, u ...