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

打表后就会发现,答案分子为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. 2017-2018-1 20155308《信息安全技术》实验二——Windows口令破解

    2017-2018-1 20155308<信息安全技术>实验二--Windows口令破解 实验原理 口令破解主要有两种方法:字典破解和暴力破解. 字典破解是指通过破解者对管理员的了解,猜测 ...

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

    学号 2016-2017-2015329 <Java程序设计>第4周学习总结 教材学习内容总结 面向对象有三大特性:封装.继承.多态 封装 封装是指,一种将抽象性函式接口的实例细节部份包装 ...

  3. windows查看系统版本号

    win+R,输入cmd,确定,打开命令窗口,输入msinfo32,注意要在英文状态下输入,回车.然后在弹出的窗口中就可以看到系统的具体版本号了.   win+R,输入cmd,确定,打开命令窗口,输入v ...

  4. java开发划分级别的标准

    一.史诗序: java开发也有一段时间了,整天茫茫碌碌,除了偶尔的小有成就感,剩下的大部分好像都在重复,你是否也遇到了这样的情况? 遇到一个小细节问题,之前不久解决过,现在却是什么都记不起来了 面对每 ...

  5. 【转载】D3D深度测试和Alpha混合

    原文:D3D深度测试和Alpha混合 1.       深度测试 a)         深度缓冲区:屏幕上每个像素点的深度信息的一块内存缓冲区.D3D通过比较当前绘制的像素点的深度和对应深度缓冲区的点 ...

  6. 【LG5022】[NOIP2018]旅行

    [LG5022][NOIP2018]旅行 题面 洛谷 题解 首先考虑一棵树的部分分怎么打 直接从根节点开始\(dfs\),依次选择编号最小的儿子即可 而此题是一个基环树 怎么办呢? 可以断掉环上的一条 ...

  7. git clone的时候报error: RPC failed; result=18错误

    因业务需求,需要把内网gitlab仓库的地址对外网访问,在gitlab前端配置了一个nginx代理服务器,来实现需求,可以在git clone的时候报error: RPC failed错误 [root ...

  8. L018-crond的生产场景经验小节

    L018-crond的生产场景经验小节 怎么说呢,其实L018这节课还是巩固crond的知识,前半堂课主要是解决上堂课老师留的作业(在L017已经更新,拉到最后),然后剩下的半堂客主要是讲解了一些生产 ...

  9. fail-fast 机制 思考

    HashMap的迭代器(Iterator)是fail-fast迭代器,而Hashtable的enumerator迭代器不是fail-fast的. Iterator支持fail-fast机制,而Enum ...

  10. hdu - 6276,2018CCPC湖南全国邀请赛A题,水题,二分

    题意: 求H的最大值,  H是指存在H篇论文,这H篇被引用的次数都大于等于H次. 思路:题意得,  最多只有N遍论文,所以H的最大值为N, 常识得知H的最小值为0. 所以H的答案在[0,N]之间,二分 ...