UVA 10375 Choose and divide(大数的表示)
2024-09-30 08:19:07
紫上给得比较奇怪,其实没有必要用唯一分解定理。我觉得这道题用唯一分解只是为了表示大数。
但是分解得到的幂,累乘的时候如果顺序很奇怪也可能溢出。其实直接边乘边除就好了。因为答案保证不会溢出,
设定一个精度范围,如果中间结果超过了精度范围就保存起来,最后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 ;
}
最新文章
- Java程序员必须掌握的8大排序算法
- Dubbo消费端错误: ClassNotFoundException: org.apache.zookeeper.proto.WatcherEvent
- 难道只有我一个人想吐槽npm这种包管理方式么
- mybatis.net insert 返回主键
- UIButton详解
- POJ 3114 Countries in War(强连通)(缩点)(最短路)
- 框架使用的技术主要是SpringMVC 在此基础上进行扩展
- c#局域网文件搬移
- 传送门(portal)
- cocos2d-x 2.2.3 之菜单分析(1)
- 自定义 select 下拉菜单
- hdu 3056 病毒侵袭持续中 AC自己主动机
- 如何解决Android SDK无法下载Package的问题(.net)
- 我的iOS-App
- Eclipse错误:Implicit super constructor ClassName is undefined for default constructor. Must define an explicit constructor
- Hadoop(十一)Hadoop IO之序列化与比较功能实现详解
- 第八章:Python基础の面向对象(二)
- 2017广东工业大学程序设竞赛E题(倒水)
- LANMP系列教程之Apache编译安装CentOS7环境
- python 学习三
热门文章
- C++的STL总结(1)
- 将图片至于jsp页面上(层)
- 分层图最短路【bzoj2834】: 回家的路
- Jmeter_Beanshell_使用Java处理JSON块(转)
- Java中keytool管理证书
- springMvc配置 中文api
- matlab 常用函数(数学建模-复习)
- SpringBoot | 第七章:过滤器、监听器、拦截器
- 性能测试学习第四天_Loadrunner概述
- 从客户端(content1=";<;img src=";/web/news/...";)中检测到有潜在危险的 Request.Form 值。