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 ...
随机推荐
- 20155301 2016-2017-2 《Java程序设计》第2周学习总结
20155301 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 教材的第三章内容主要分为两大方面: 一.程序中的数据类型,变量和运算符,主要讲述了各种类型的 ...
- 【LOJ6433】【PKUSC2018】最大前缀和
[LOJ6433][PKUSC2018]最大前缀和 题面 题目描述 小 C 是一个算法竞赛爱好者,有一天小 C 遇到了一个非常难的问题:求一个序列的最大子段和. 但是小 C 并不会做这个题,于是小 C ...
- [IOI2011]Race 点分治
[IOI2011]Race LG传送门 点分治板子题. 直接点分治统计,统计的时候开个桶维护下就好了. 注(tiao)意(le)细(hen)节(jiu). #include<cstdio> ...
- Yii2 模块module笔记
包含内容: 使用GII新建module 建立子模块 在其他控制器中调用模块的操作(action) 1. 使用Gii工具新建module 注意模块的路径,我们没有写backend\modules\Art ...
- Tp框架之命名空间
命名空间,相当于虚拟目录 实现自动加载类的机制 初始命名空间:Library文件夹 初始命名空间下面有很多根命名空间: 1.Library里面的文件夹 2.APP的模块文件夹 在tp框架中,只有这两个 ...
- 一个IP可以登几个拼多多后台 拼多多如何推广营销
想要在拼多多上开双店?担心一根网线会引起IP冲突?那么一根网线可以登几个拼多多后台呢?有数据显示,挂双店是没有问题的,甚至可以多开.那么解决了一根网线的事情,要怎么对自己的店铺进行营销推广呢?下面是小 ...
- selenium自动化之处理浏览器警告弹窗
有的网站会弹出类似如下图的警告弹窗,你会发现这种弹窗在html源码中怎么也定位不到,接下来将介绍这种弹窗的处理方式. 其实这种弹窗是不属于html的元素的,他是属于浏览器自带的弹窗,所以用定位元素的方 ...
- 网络流dinic模板,邻接矩阵+链式前向星
//这个是邻接矩阵的#include<iostream> #include<queue> #include<string.h> #include<stdio. ...
- Centos7下安装Oracle11g r2
我的centos7是在virtualbox下安装的,安装Oracle安装了好久好久,最开始的时候在网上找的两个文章,按照步骤装,有一篇写着装的时候有灰色的竖线,直接按space键或者鼠标右键close ...
- Variable() placeholder() constant() 的区别
转载来自: http://www.studyai.com/article/33e22cef42274e8a