HDU4043_FXTZ II
题目描述的意思就不说了,自己考虑的时候就是在所有的排列中,碰到大于前面最大的出现数字的时候就乘以一个二分之一,然后求和。
打表后就会发现,答案分子为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的更多相关文章
- 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 ...
- 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 ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- 统计分析中Type I Error与Type II Error的区别
统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- [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 ...
- [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 ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- Azkaban 工作流调度器
Azkaban 工作流调度器 1 概述 1.1 为什么需要工作流调度系统 a)一个完整的数据分析系统通常都是由大量任务单元组成,shell脚本程序,java程序,mapreduce程序.hive脚本等 ...
- jenkins统计单元测试的覆盖率
前提:单元测试和被测代码在一个仓库 maven的pom配置 依赖增加 <dependency> <groupId>org.jacoco</groupId> < ...
- (三)Hololens Unity 开发之 语音识别
学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (三)Hololens Unity 开发之 语音识别 Hol ...
- Maven学习(五)-----如何从Maven远程存储库下载?
如何从Maven远程存储库下载? 根据 Apache Maven 的说明: Downloading in Maven is triggered by a project declaring a dep ...
- javaweb(十五)——JSP基础语法
任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依然有其自己扩充的语法,而且在JSP中,所有的JAVA语句都可以使用. 一.JSP模版元素 JSP页面中的HTML内容称之 ...
- linux、WINDOWS命令行下查找和统计行数
linux : 例子: netstat -an | grep TIME_WAIT | wc -l | 管道符 grep 查找命令 wc 统计命令 windows: 例子: netstat -an | ...
- OpenCL入门:(一:Intel核心显卡OpenCL环境搭建)
组装的电脑没带独立显卡,用的是CPU自带的核显,型号是Intel HD Graphics 530,关于显卡是否可以使用OpenCL,可以下载GPU-Z软件查看. 本文在Windows 10 64位系统 ...
- HTML5 + CSS3 实现地球绕太阳公转
使用的是正面视角,主要是用 HTML5 + CSS3 来实现,JS只是用来画图. test.html: <!DOCTYPE html> <html> <head> ...
- 【第二章】MySQL数据库基于Centos7.3-部署
一.MySQL数据库的官方网址: https://www.mysql.com/ https://www.oracle.com/ http://dev.mysql.com/doc/refman/5.7/ ...
- 详解Python中的下划线
本文将讨论Python中下划线(_)字符的使用方法.我们将会看到,正如Python中的很多事情,下划线的不同用法大多数(并非所有)只是常用惯例而已. 单下划线(_) 通常情况下,会在以下3种场景中使用 ...