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

打表后就会发现,答案分子为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. 20155226 实验四 Android开发基础

    20155226第四次实验报告 一.实验内容及步骤 Android Stuidio的安装测试: 安装 Android Stuidio 完成Hello World, 要求修改res目录中的内容,Hell ...

  2. Postgresql 远程连接配置

    原文地址:http://blog.chinaunix.net/uid-20684384-id-1895247.html 1. 设置远程访问认证机制 编辑 $POSTGRES/data/pg_hba.c ...

  3. 跨域发送HTTP请求详解

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述几种跨域发HTTP请求的几种方法,POST请求,GET请求 目录: 一,采用JsonP的方式(只能 ...

  4. NUnit基本使用方法

    通常的单元测试框架都以他们支持的语言的开头字母加上Unit作为名字,他们统称为xUnit框架.C++的叫做CppUnit,Java的叫做JUnit,.Net的叫做NUnit.当然不是所有的都这么命名, ...

  5. 类的扩展之 DataReader的扩展

    看了关于DataReader的扩展,发现能节省很多代码.从数据库读取数据最原始方法就是while()然后做循环,如果数据库添加一个字段那么你所有读取数据库的方法全部添加.通过扩展这个类就摆脱了这种令人 ...

  6. Select 、Poll 和 Epoll

    作用 Epoll 和 Select 的作用都是为了多I/O同步复用的问题,利用Epoll.Poll或Select函数指定内核监听多个I/O的读.写.异常事件,避免每一个I/O都指定一个处理线程,导致开 ...

  7. cinder的组件

    跟nova相似,cinder也有很多组件,每个组件负责各自的业务,然后共同协作完成volume的管理.组件之间的通信方式与nova个组件之间的通信方式相同,都是通过消息队列进行通信. cinder-a ...

  8. conda环境管理

    查看环境 conda env list 创建环境 conda create -n python36 python=3.6 进入环境 source activate python36 activate ...

  9. Professional Books

    Machine Learning:     Pattern Recognition and Machine Learning(PRML)    https://mqshen.gitbooks.io/p ...

  10. Visiting a Friend(思维)

    Description Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is l ...