UVA - 12298 Super Poker II NTT

链接

Vjudge

思路

暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数"。

错误

我也不知道,改着改着自己就A了

思路

  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const ll N=1e7+7,mod=39582418599937LL;
  5. char s;
  6. bool vis[N];
  7. ll A[4][N],len[4],r[N];
  8. ll read() {
  9. ll x=0,f=1;s=getchar();
  10. for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
  11. for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
  12. return x*f;
  13. }
  14. ll mul(ll u,ll v){return ((u*v-(ll)((long double)u/mod*v+1e-8)*mod)%mod+mod)%mod;}
  15. ll q_pow(ll a,ll b) {
  16. ll ans=1;
  17. while(b) {
  18. if(b&1) ans=mul(ans,a);
  19. a=mul(a,a);
  20. b>>=1;
  21. }
  22. return ans;
  23. }
  24. void ntt(ll *a,ll limit,ll type) {
  25. for(ll i=0;i<=limit;++i)
  26. if(i<r[i]) swap(a[i],a[r[i]]);
  27. for(ll mid=1;mid<limit;mid<<=1) {
  28. ll Wn=q_pow(5,(mod-1)/(mid<<1));
  29. for(ll i=0;i<limit;i+=(mid<<1)) {
  30. for(ll j=0,w=1;j<mid;++j,w=mul(w,Wn)) {
  31. ll x=a[i+j],y=mul(w,a[i+j+mid]);
  32. a[i+j]=(x+y)%mod;
  33. a[i+j+mid]=(x+mod-y)%mod;
  34. }
  35. }
  36. }
  37. if(type==-1) {
  38. reverse(&a[1],&a[limit]);
  39. ll inv=q_pow(limit,mod-2);
  40. for(ll i=0;i<=limit;++i) a[i]=mul(a[i],inv);
  41. }
  42. }
  43. void Euler(ll b) {
  44. for(ll i=2;i<=b;++i) {
  45. if(!vis[i]) {
  46. for(ll j=i+i;j<=b;j+=i)
  47. vis[j]=1;
  48. }
  49. }
  50. }
  51. int main() {
  52. Euler(50000);
  53. while(233) {
  54. ll a=read(),b=read(),c=read();
  55. if(!a&&!b&&!c) break;
  56. memset(A,0,sizeof(A));
  57. ll limit=1,l=0;
  58. for(ll i=2;i<=b;++i) A[0][i]=A[1][i]=A[2][i]=A[3][i]=vis[i];
  59. for(ll i=1;i<=c;++i) {
  60. ll x=read();
  61. if(s=='S') A[0][x]=0;
  62. else if(s=='H') A[1][x]=0;
  63. else if(s=='C') A[2][x]=0;
  64. else A[3][x]=0;
  65. }
  66. while(limit<=4LL*b) limit<<=1,l++;
  67. for(ll i=0;i<=limit;++i)
  68. r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
  69. ntt(A[0],limit,1),ntt(A[1],limit,1),ntt(A[2],limit,1),ntt(A[3],limit,1);
  70. for(ll i=0;i<=limit;++i) A[0][i]=mul(mul(A[0][i],A[1][i]),mul(A[2][i],A[3][i]));
  71. ntt(A[0],limit,-1);
  72. for(ll i=a;i<=b;++i) printf("%lld\n",A[0][i]);
  73. puts("");
  74. }
  75. return 0;
  76. }

UVA - 12298 Super Poker II NTT的更多相关文章

  1. UVA - 12298 Super Poker II (FFT+母函数)

    题意:有四种花色的牌,每种花色的牌中只能使用数值的约数个数大于2的牌.现在遗失了c张牌.每种花色选一张,求值在区间[a,b]的每个数值的选择方法有多少. 分析:约数个数大于2,即合数.所以先预处理出5 ...

  2. UVA 12298 Super Poker II (FFT)

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

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

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

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

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

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

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

  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. centos7内核升级及curl访问https证书过期处理

    centos7内核升级及curl访问https证书过期处理 先看下当前系统的linux内核版本 uname -r 3.10.0-229.el7.x86_64 升级步骤 1.rpm --import h ...

  2. VUE-008-通过路由 router.push 传递 query 参数(路由 path 识别,请求链接显示参数传递)

    在前端页面表单列表修改时,经常需要在页面切换的时候,传递需要修改的表单内容,通常可通过路由进行表单参数的传递. 首先,配置页面跳转路由.在 router/index.js 中配置相应的页面跳转路由,如 ...

  3. windy数

    windy数指的是相邻两位差至少为2的数.问区间[a,b]中有多少个windy数 调了半个多小时,不过调出来之后对数位dp理解大大加深 #include<iostream> #includ ...

  4. SpringBoot打包不同配置profile

    1.application.properties添加变量 spring.profiles.active=@activatedProperties@ 2.pom中添加变量配置 <profiles& ...

  5. VS Code mac版全局搜索失效最简单解法

    网上百度到的一些说法,说是添加以下命令行 "search.exclude": { "system/": true, "!/system/**/*.ps ...

  6. Mysql8安装与配置

    网上的教程有很多,基本上大同小异.但是安装软件有时就可能因为一个细节安装失败.我也是综合了很多个教程才安装好的,所以本教程可能也不是普遍适合的. 安装环境:win7 1.下载zip安装包: MySQL ...

  7. notify.min.js

    /*! * @wcjiang/notify v2.0.11 * JS achieve the browser title flashing , scrolling, voice prompts , c ...

  8. Java中的过滤器,拦截器,监听器---------简单易懂的介绍

    过滤器: 过滤器其主要特点在于:取你需要的东西,忽视那些不需要的东西!在程序中,你希望选择中篇文章中的所有数字,你就可以针对性的挑选数字! 拦截器: 拦截器其主要特点在于:针对你不要的东西进行拦截,比 ...

  9. FB面经 Prepare: Largest Island

    Find largest island in a board package fb; public class LargestIsland { public int findLargestIsland ...

  10. springboot引入AOP

    AOP是Aspect Oriented Programming的缩写,意为面向切面编程.通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是spring框架的一个重要内容,她通过对 ...