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 ...
随机推荐
- 2017-2018-1 20155308《信息安全技术》实验二——Windows口令破解
2017-2018-1 20155308<信息安全技术>实验二--Windows口令破解 实验原理 口令破解主要有两种方法:字典破解和暴力破解. 字典破解是指通过破解者对管理员的了解,猜测 ...
- 2016-2017-2015329 《Java程序设计》第4周学习总结
学号 2016-2017-2015329 <Java程序设计>第4周学习总结 教材学习内容总结 面向对象有三大特性:封装.继承.多态 封装 封装是指,一种将抽象性函式接口的实例细节部份包装 ...
- windows查看系统版本号
win+R,输入cmd,确定,打开命令窗口,输入msinfo32,注意要在英文状态下输入,回车.然后在弹出的窗口中就可以看到系统的具体版本号了. win+R,输入cmd,确定,打开命令窗口,输入v ...
- java开发划分级别的标准
一.史诗序: java开发也有一段时间了,整天茫茫碌碌,除了偶尔的小有成就感,剩下的大部分好像都在重复,你是否也遇到了这样的情况? 遇到一个小细节问题,之前不久解决过,现在却是什么都记不起来了 面对每 ...
- 【转载】D3D深度测试和Alpha混合
原文:D3D深度测试和Alpha混合 1. 深度测试 a) 深度缓冲区:屏幕上每个像素点的深度信息的一块内存缓冲区.D3D通过比较当前绘制的像素点的深度和对应深度缓冲区的点 ...
- 【LG5022】[NOIP2018]旅行
[LG5022][NOIP2018]旅行 题面 洛谷 题解 首先考虑一棵树的部分分怎么打 直接从根节点开始\(dfs\),依次选择编号最小的儿子即可 而此题是一个基环树 怎么办呢? 可以断掉环上的一条 ...
- git clone的时候报error: RPC failed; result=18错误
因业务需求,需要把内网gitlab仓库的地址对外网访问,在gitlab前端配置了一个nginx代理服务器,来实现需求,可以在git clone的时候报error: RPC failed错误 [root ...
- L018-crond的生产场景经验小节
L018-crond的生产场景经验小节 怎么说呢,其实L018这节课还是巩固crond的知识,前半堂课主要是解决上堂课老师留的作业(在L017已经更新,拉到最后),然后剩下的半堂客主要是讲解了一些生产 ...
- fail-fast 机制 思考
HashMap的迭代器(Iterator)是fail-fast迭代器,而Hashtable的enumerator迭代器不是fail-fast的. Iterator支持fail-fast机制,而Enum ...
- hdu - 6276,2018CCPC湖南全国邀请赛A题,水题,二分
题意: 求H的最大值, H是指存在H篇论文,这H篇被引用的次数都大于等于H次. 思路:题意得, 最多只有N遍论文,所以H的最大值为N, 常识得知H的最小值为0. 所以H的答案在[0,N]之间,二分 ...