紫上给得比较奇怪,其实没有必要用唯一分解定理。我觉得这道题用唯一分解只是为了表示大数。

但是分解得到的幂,累乘的时候如果顺序很奇怪也可能溢出。其实直接边乘边除就好了。因为答案保证不会溢出,

设定一个精度范围,如果中间结果超过了精度范围就保存起来,最后sort一遍从两端同时乘就不会溢出了。

/*********************************************************
* --------------Tyrannosaurus--------- *
* author AbyssalFish *
**********************************************************/
/*
数的表示,唯一表示,固定进制,变进制(编码),素因子幂
不唯一表示 很多
*/
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e4+; vector<double> ans_fac;
const double up_b = 1e8, low_b = 1e-; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int p, q, r, s;
while(~scanf("%d%d%d%d", &p, &q, &r, &s)){
int m = max(p, r), x = p-q, y = r-s;
double ans = ;
for(int i = ; i <= m; i++){
int t = ;
if(q < i && i <= p) t++;
if(i <= x) t--;
if(s < i && i <= r) t--;
if(i <= y) t++;
if(t){
if(t < )
while(ans /= i, ++t) ;
else
do ans *= i; while( --t) ;
if(ans > up_b || ans < low_b) {
ans_fac.push_back(ans);
ans = ;
}
}
}
if(ans_fac.size()){
sort(ans_fac.begin(),ans_fac.end());
int i = , j = ans_fac.size()-;
while(i < j){
ans *= ans_fac[i++]*ans_fac[j--];
}
if(i == j) ans *= ans_fac[i];
ans_fac.clear();
}
printf("%.5lf\n", ans);
}
return ;
}

UVA 10375 Choose and divide(大数的表示)的更多相关文章

  1. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  2. 【暑假】[数学]UVa 10375 Choose and divide

    UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...

  3. UVa 10375 - Choose and divide(唯一分解定理)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA 10375 Choose and divide【唯一分解定理】

    题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...

  5. UVA 10375 Choose and divide

    n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...

  6. uva10375 Choose and Divide(唯一分解定理)

    uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...

  7. UVA10375 Choose and divide 质因数分解

    质因数分解: Choose and divide Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  8. UVa 10375 (唯一分解定理) Choose and divide

    题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...

  9. UVA 10328 - Coin Toss dp+大数

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

随机推荐

  1. Linux中常用压缩命令

    .zip格式压缩 zip 压缩文件名 源文件 压缩文件 zip -r 压缩文件名 源目录 压缩目录 .zip格式解压缩 unzip 压缩文件 解压.zip文件 .gz格式压缩 gzip 源文件 压缩为 ...

  2. Maven项目骨架搭建

    1. 如何使用Maven的archetype快速生成一个新项目 2. Maven之自定义archetype生成项目骨架(一) 3. 使用maven3 创建自定义的archetype 4. 使用mave ...

  3. 在pom包中添加spring-boot-starter-test包引用

    有很多网友会时不时的问我,spring boot项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下spring boot 如何开发.调试.打包到最后的投产上线. 开发阶段 单元 ...

  4. HDU2048 神、上帝以及老天爷

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2048 看书发现了这道题,刚开始没理解题意,以为是中奖的概率,---> 1/n 后来知道了是典型的错排 ...

  5. Duff and Meat(贪心)

    Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day ...

  6. ReflectionUtil

    import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang ...

  7. ProtocBuffer安装

    学习protocolhttp://www.jianshu.com/p/fa126a8535a0 mac安装protocbuff: 下边总结一下安装流程: 查看官方文档源码在 https://githu ...

  8. eclipse ctrl+h

    之前我的eclipse使用ctrl + h 出现的总是Plug-in Search ,总是需要点那个小三角才能找到File Search ,深感使用不便, 修改方法:Window->Genera ...

  9. Shell变量赋值语句不能有空格

    a = 1是错的!!!!!只有 a=1才是正确的.

  10. Shell编程中的条件判断(条件测试)

    Shell中的条件判断(测试)类型: 1) 整数测试 2) 字符测试 3) 文件测试 条件测试的表达式:        (注: expression 与 [] 之间空格不能省略) [ expressi ...