传送门:https://vjudge.net/problem/HDU-6822

题意:给你一张无限的纸有四种折叠方式,并且在n次折叠后减两刀问最后纸张数量的数学期望。

思路:我们要得到一个通项公式对于不同折叠情况下的最后所得纸张数量,因为从上往下对折和从下往上对折是一样的,同理从左忘右对折和从右往左对折也是一样的那么假设从上往下对折k次那么从左往右对折n-k次,那么横线有2k+1条竖线有2n-k+1条,因为最后是从中心位置横竖减两刀,所以最后的纸片数量就是(2k+1)*(2n-k+1)个。接下来就是对二项式定理的化简了。

  1. 1 //#include<bits/stdc++.h>
  2. 2 #include<time.h>
  3. 3 #include <set>
  4. 4 #include <map>
  5. 5 #include <stack>
  6. 6 #include <cmath>
  7. 7 #include <queue>
  8. 8 #include <cstdio>
  9. 9 #include <string>
  10. 10 #include <vector>
  11. 11 #include <cstring>
  12. 12 #include <utility>
  13. 13 #include <cstring>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 #include <list>
  17. 17 using namespace std;
  18. 18 #define eps 1e-10
  19. 19 #define PI acos(-1.0)
  20. 20 #define lowbit(x) ((x)&(-x))
  21. 21 #define zero(x) (((x)>0?(x):-(x))<eps)
  22. 22 #define mem(s,n) memset(s,n,sizeof s);
  23. 23 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
  24. 24 typedef long long ll;
  25. 25 typedef unsigned long long ull;
  26. 26 const int maxn=6e6+5;
  27. 27 const int Inf=0x7f7f7f7f;
  28. 28 const ll Mod=1e9+7;
  29. 29 const int N=3e3+5;
  30. 30 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
  31. 31 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
  32. 32 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
  33. 33 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
  34. 34 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
  35. 35 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
  36. 36 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
  37. 37 int Abs(int n) {
  38. 38 return (n ^ (n >> 31)) - (n >> 31);
  39. 39 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
  40. 40 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
  41. 41 需要计算 n 和 -1 的补码,然后进行异或运算,
  42. 42 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
  43. 43 }
  44. 44 ll binpow(ll a, ll b,ll c) {
  45. 45 ll res = 1;
  46. 46 while (b > 0) {
  47. 47 if (b & 1) res = res * a%c;
  48. 48 a = a * a%c;
  49. 49 b >>= 1;
  50. 50 }
  51. 51 return res%c;
  52. 52 }
  53. 53 void extend_gcd(ll a,ll b,ll &x,ll &y)
  54. 54 {
  55. 55 if(b==0) {
  56. 56 x=1,y=0;
  57. 57 return;
  58. 58 }
  59. 59 extend_gcd(b,a%b,x,y);
  60. 60 ll tmp=x;
  61. 61 x=y;
  62. 62 y=tmp-(a/b)*y;
  63. 63 }
  64. 64 ll mod_inverse(ll a,ll m)
  65. 65 {
  66. 66 ll x,y;
  67. 67 extend_gcd(a,m,x,y);
  68. 68 return (m+x%m)%m;
  69. 69 }
  70. 70 ll eulor(ll x)
  71. 71 {
  72. 72 ll cnt=x;
  73. 73 ll ma=sqrt(x);
  74. 74 for(int i=2;i<=ma;i++)
  75. 75 {
  76. 76 if(x%i==0) cnt=cnt/i*(i-1);
  77. 77 while(x%i==0) x/=i;
  78. 78 }
  79. 79 if(x>1) cnt=cnt/x*(x-1);
  80. 80 return cnt;
  81. 81 }
  82. 82 int mod=998244353;
  83. 83 int main()
  84. 84 {
  85. 85 ios
  86. 86 int T;
  87. 87 ll n;
  88. 88 cin>>T;
  89. 89 while(T--)
  90. 90 {
  91. 91 cin>>n;
  92. 92 ll c2=binpow(2,n,mod);
  93. 93 ll c3=binpow(3,n,mod);
  94. 94 ll c22=binpow(c2,mod-2,mod);
  95. 95 cout<<(1+c2+2*c3*c22)%mod<<endl;
  96. 96 }
  97. 97 return 0;
  98. 98 }

Paperfolding HDU - 6822的更多相关文章

  1. hdu 6822 Paperfolding 规律+排列组合+逆元

    题意: 给你一片纸,你可以对它进行四种操作,分别是向上.向下.向左.向右对折.把对折之后的纸片横向剪开,再纵向剪开(十字架剪开) 问你你能剪出来的纸片的期望个数 题解(参考:https://blog. ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. 2019牛客多校第五场C generator 2(BSGS)题解

    题意: 传送门 已知递推公式\(x_i = a*x_{i - 1} + b\mod p\),\(p\)是素数,已知\(x_0,a,b,p\),给出一个\(n\)和\(v\),问你满足\(x_i = v ...

  2. JVM 报 GC Overhead limit exceeded 是什么意思?

    默认情况下,并不是等堆内存耗尽,才会报 OutOfMemoryError,而是如果 JVM 觉得 GC 效率不高,也会报这个错误. 那么怎么评价 GC 效率不高呢?来看下源码: 呢?来看下源码gcOv ...

  3. webpack4.0源码解析之打包后js文件分析

    首先,init之后创建一个简单的webpack基本的配置,在src目录下创建两个js文件(一个主入口文件和一个非主入口文件)和一个html文件,package.json,webpack.config. ...

  4. uni-app 支持第三方 H5 离线包

    uni-app 支持第三方 H5 离线包 https://uniapp.dcloud.io/ https://github.com/dcloudio/uni-app refs xgqfrms 2012 ...

  5. URL parser All In One

    URL parser All In One const url = new URL(`https://admin:1234567890@cdn.xgqfrms.xyz:8080/logo/icon.p ...

  6. SSL/TLS All In One

    SSL/TLS All In One HTTPS SSL/TLS 的工作原理 https://www.websecurity.digicert.com/zh/cn/security-topics/ho ...

  7. git config [section] solutions

    git config [section] solutions fix git [section] warnings global config $ vim ~/.gitconfig [user] em ...

  8. 阅文集团 招聘官网 bug

    阅文集团 招聘官网 bug https://join.yuewen.com/ 前端开发 zxx.jpg 张鑫旭 https://qidian.gtimg.com/yuewen/join/css/ima ...

  9. 为什么说USDN是一种应用型稳定币?

    USDN是由NGK Global出品的一种新型稳定币系统,里面是涵盖了包括货币供需.Bancor.抵押借贷等在内的一整套算法.该稳定币构想一经提出,便在社区引发了不小的热度. 官方对于USDN的定位是 ...

  10. K8S线上集群排查,实测排查Node节点NotReady异常状态

    一,文章简述 大家好,本篇是个人的第 2 篇文章.是关于在之前项目中,k8s 线上集群中 Node 节点状态变成 NotReady 状态,导致整个 Node 节点中容器停止服务后的问题排查. 文章中所 ...