题目描述的意思就不说了,自己考虑的时候就是在所有的排列中,碰到大于前面最大的出现数字的时候就乘以一个二分之一,然后求和。

打表后就会发现,答案分子为1*3*5*……*(2*n-1);分母为2*4*6*……*(2*n),这样就很简单了。

直接保存每一个因子出现的次数,然后。。。就可以了。。。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define M 1000000
  5. #define maxn 1011
  6. using namespace std;
  7.  
  8. struct node{
  9. int top,s[];
  10. void init()
  11. {
  12. for (int i=; i<=top; i++) s[i]=;
  13. top=,s[]=;
  14. }
  15. void mul(int x)
  16. {
  17. for (int i=; i<=top; i++) s[i]*=x;
  18. for (int i=; i<top; i++)
  19. if (s[i]>=M) s[i+]+=s[i]/M,s[i]%=M;
  20. while (s[top]>=M) s[top+]=s[top]/M,s[top]%=M,top++;
  21. }
  22. void output()
  23. {
  24. printf("%d",s[top]);
  25. for (int i=top-; i>=; i--) printf("%06d",s[i]);
  26. }
  27. }ans1,ans2;
  28.  
  29. int a[maxn],pri[maxn],Pnum=;
  30. bool b[maxn];
  31.  
  32. void getprim()
  33. {
  34. for (int i=; i<maxn; i++)
  35. {
  36. if (b[i]) continue;
  37. pri[++Pnum]=i;
  38. for (int j=i+i; j<maxn; j+=i) b[j]=true;
  39. }
  40. }
  41.  
  42. void add(int x,int v)
  43. {
  44. for (int i=; pri[i]<=x; i++)
  45. {
  46. while (x%pri[i]==) x/=pri[i],a[i]+=v;
  47. }
  48. }
  49.  
  50. int main()
  51. {
  52. int T,n;
  53. getprim();
  54. scanf("%d",&T);
  55. while (T--)
  56. {
  57. scanf("%d",&n);
  58. memset(a,,sizeof a);
  59. for (int i=; i<=*n; i+=) add(i,);
  60. for (int i=; i<=*n; i+=) add(i,-);
  61. ans1.init(),ans2.init();
  62. for (int i=; i<=Pnum; i++)
  63. {
  64. while (a[i]>) ans1.mul(pri[i]),a[i]--;
  65. while (a[i]<) ans2.mul(pri[i]),a[i]++;
  66. }
  67. ans1.output();
  68. printf("/");
  69. ans2.output();
  70. printf("\n");
  71. }
  72. return ;
  73. }

HDU4043_FXTZ II的更多相关文章

  1. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  2. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  3. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  4. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

  5. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  6. [LeetCode] Guess Number Higher or Lower II 猜数字大小之二

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  7. [LeetCode] Number of Islands II 岛屿的数量之二

    A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...

  8. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  9. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. 20155301 2016-2017-2 《Java程序设计》第2周学习总结

    20155301 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 教材的第三章内容主要分为两大方面: 一.程序中的数据类型,变量和运算符,主要讲述了各种类型的 ...

  2. 【LOJ6433】【PKUSC2018】最大前缀和

    [LOJ6433][PKUSC2018]最大前缀和 题面 题目描述 小 C 是一个算法竞赛爱好者,有一天小 C 遇到了一个非常难的问题:求一个序列的最大子段和. 但是小 C 并不会做这个题,于是小 C ...

  3. [IOI2011]Race 点分治

    [IOI2011]Race LG传送门 点分治板子题. 直接点分治统计,统计的时候开个桶维护下就好了. 注(tiao)意(le)细(hen)节(jiu). #include<cstdio> ...

  4. Yii2 模块module笔记

    包含内容: 使用GII新建module 建立子模块 在其他控制器中调用模块的操作(action) 1. 使用Gii工具新建module 注意模块的路径,我们没有写backend\modules\Art ...

  5. Tp框架之命名空间

    命名空间,相当于虚拟目录 实现自动加载类的机制 初始命名空间:Library文件夹 初始命名空间下面有很多根命名空间: 1.Library里面的文件夹 2.APP的模块文件夹 在tp框架中,只有这两个 ...

  6. 一个IP可以登几个拼多多后台 拼多多如何推广营销

    想要在拼多多上开双店?担心一根网线会引起IP冲突?那么一根网线可以登几个拼多多后台呢?有数据显示,挂双店是没有问题的,甚至可以多开.那么解决了一根网线的事情,要怎么对自己的店铺进行营销推广呢?下面是小 ...

  7. selenium自动化之处理浏览器警告弹窗

    有的网站会弹出类似如下图的警告弹窗,你会发现这种弹窗在html源码中怎么也定位不到,接下来将介绍这种弹窗的处理方式. 其实这种弹窗是不属于html的元素的,他是属于浏览器自带的弹窗,所以用定位元素的方 ...

  8. 网络流dinic模板,邻接矩阵+链式前向星

    //这个是邻接矩阵的#include<iostream> #include<queue> #include<string.h> #include<stdio. ...

  9. Centos7下安装Oracle11g r2

    我的centos7是在virtualbox下安装的,安装Oracle安装了好久好久,最开始的时候在网上找的两个文章,按照步骤装,有一篇写着装的时候有灰色的竖线,直接按space键或者鼠标右键close ...

  10. Variable() placeholder() constant() 的区别

    转载来自: http://www.studyai.com/article/33e22cef42274e8a