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

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

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

#include <iostream>
#include <cstdio>
#include <cstring>
#define M 1000000
#define maxn 1011
using namespace std; struct node{
int top,s[];
void init()
{
for (int i=; i<=top; i++) s[i]=;
top=,s[]=;
}
void mul(int x)
{
for (int i=; i<=top; i++) s[i]*=x;
for (int i=; i<top; i++)
if (s[i]>=M) s[i+]+=s[i]/M,s[i]%=M;
while (s[top]>=M) s[top+]=s[top]/M,s[top]%=M,top++;
}
void output()
{
printf("%d",s[top]);
for (int i=top-; i>=; i--) printf("%06d",s[i]);
}
}ans1,ans2; int a[maxn],pri[maxn],Pnum=;
bool b[maxn]; void getprim()
{
for (int i=; i<maxn; i++)
{
if (b[i]) continue;
pri[++Pnum]=i;
for (int j=i+i; j<maxn; j+=i) b[j]=true;
}
} void add(int x,int v)
{
for (int i=; pri[i]<=x; i++)
{
while (x%pri[i]==) x/=pri[i],a[i]+=v;
}
} int main()
{
int T,n;
getprim();
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
memset(a,,sizeof a);
for (int i=; i<=*n; i+=) add(i,);
for (int i=; i<=*n; i+=) add(i,-);
ans1.init(),ans2.init();
for (int i=; i<=Pnum; i++)
{
while (a[i]>) ans1.mul(pri[i]),a[i]--;
while (a[i]<) ans2.mul(pri[i]),a[i]++;
}
ans1.output();
printf("/");
ans2.output();
printf("\n");
}
return ;
}

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. Potree学习总结

    一.      简介 基于Web端的三维模型展示,这里仅介绍Three.js和Potree. Three.js 是一款基于WebGL的运行在浏览器中的 3D 开源引擎,用它创建各种三维场景.它类似于M ...

  2. c++ 全局变量

    一.全局变量 声明 全局变量的定义和一般变量定义相同,不同的就是它的位置.一般会放在所有共享函数的前边. 作用 在函数间共享数据. 二.全局变量的运用 三.作业: 写出代码运行结果: ; //0 in ...

  3. slqite3练习

    连接 import sqlite3 con = sqlite3.connect(":memory:") c = con.cursor() # Create table c.exec ...

  4. 人脸识别引擎SeetaFaceEngine中Identification模块使用的测试代码

    人脸识别引擎SeetaFaceEngine中Identification模块用于比较两幅人脸图像的相似度,以下是测试代码: int test_recognize() { const std::stri ...

  5. day 7 __new___

    1 __new__方法 创建对象 实质是:调用父类的__new__方法创建的对象 class Dog(object): def __init__(self): print("---init方 ...

  6. BZOJ3174. [TJOI2013]拯救小矮人(dp)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3174 题解 其实此题并不需要那么多YY的部分. 我们考虑若干个小矮人逃出的顺序.若跳出的 ...

  7. C++自学第二课:对象和类的概念

    既然是C++,比C语言多了最重要的概念:面向对象. 面向对象?对象是什么?Girlfriend? 我天天面向她也没学会C++. 我觉得对象就是有统一特征的一类编程目标. 打个比方说墙上有个开关,我一按 ...

  8. and_or_not 逻辑运算符的操作注解!

    python操作:

  9. 云主机启动提示Booting from Hard Disk GRUB

    版本:Openstack ocata 系统:centos7.3 环境:VMware workstation12 解决方法: 或者

  10. 微软职位内部推荐-Principal Group Program Manager

    微软近期Open的职位: Standard job title: Principal Group Program Manager Discipline: Program Management Prod ...