Codeforces 621 D Rat Kwesh and Cheese
来源:互联网 发布:淘宝解冻的金额在哪 编辑:程序博客网 时间:2024/05/21 11:34
传送门:
http://codeforces.com/contest/621/problem/D
double 1.07*10的308位
long double 简直神器 4900多位
此题log里面会卡负数,因此可以用long double 然后一个log 就可以了!!
今天想叉掉一个B题暴力写的,然后输出文件手点的太快,导致数据没写完,最后invalid input 简直可惜啊!!!!
#include <iostream>#include <cmath>#define double long doubleusing namespace std;double get2(double x, double y, double z) { //(x ^ y) ^ z return y * z * log(x);}const double eps = 1e-10;bool bigger(double a, double b) { //a > b return a - b > 0; //-eps;}bool equal(double a, double b) { return abs(a - b) < eps;}double best;int best_pos;int pos;void try1(double x, double y, double z, bool sure = false) { ++ pos; //x ^ y ^ z double val = pow(y, z) * log(x); if (bigger(val, best) || sure) { best = val; best_pos = pos; }}void try2(double x, double y, double z, bool sure = false) { ++ pos; //(x ^ y) ^ z double val = y * z * log(x); if (bigger(val, best) || sure) { best = val; best_pos = pos; }}int main(){ double x, y, z; cin >> x >> y >> z; try1(x, y, z, true); try1(x, z, y); try2(x, y, z); try2(x, z, y); try1(y, x, z); try1(y, z, x); try2(y, x, z); try2(y, z, x); try1(z, x, y); try1(z, y, x); try2(z, x, y); try2(z, y, x); //cout<<best<<endl; if (best_pos == 1) cout << "x^y^z\n"; else if (best_pos == 2) cout << "x^z^y\n"; else if (best_pos == 3) cout << "(x^y)^z\n"; else if (best_pos == 4) cout << "(x^z)^y\n"; else if (best_pos == 5) cout << "y^x^z\n"; else if (best_pos == 6) cout << "y^z^x\n"; else if (best_pos == 7) cout << "(y^x)^z\n"; else if (best_pos == 8) cout << "(y^z)^x\n"; else if (best_pos == 9) cout << "z^x^y\n"; else if (best_pos == 10) cout << "z^y^x\n"; else if (best_pos == 11) cout << "(z^x)^y\n"; else if (best_pos == 12) cout << "(z^y)^x\n"; return 0;}
不过题解给的思想还是蛮给力的,毕竟long double
能解决的位数也是有限的,属于是水过,标解是这样的,我们还是取双log,分成三类,
1.如果a,b,c都是大于1的,那么好办
2.如果至少有一个是大于1的,那么就要把大于1的作为底,因为如果把小于1的做底,那么结果永远是小于1的,那么我们就可以不去比较那些会使得值为负数的表达式,就ok了
3.如果三个数都小于1的话,那么我们可以将底数取倒数,然后就比较最小值就ok了,简直机智啊!orz
2 0
- Codeforces 621 D Rat Kwesh and Cheese
- 【17.00%】【codeforces 621D】Rat Kwesh and Cheese
- Codeforces 621D Rat Kwesh and Cheese【Long Double】
- CodeForces 621 D.Rat Kwesh and Cheese(水~)
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2)D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese(数学 | 复数)
- Codeforces #341 D. Rat Kwesh and Cheese 浮点数处理技巧 好题
- Codeforces Round #341 (Div. 2) Editorial D - Rat Kwesh and Cheese(数学,高精度)
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese (pow,复数
- CF621D - Rat Kwesh and Cheese
- codeforce341 D题 Rat Kwesh and Cheese(复数)
- 暑假-动态规划 III-D - FatMouse and Cheese
- [Codeforces]Fox Dividing Cheese
- 【CODEFORCES】 D. Gargari and Permutations
- hdu1078FatMouse and Cheese
- hdu1078 FatMouse and Cheese
- iOS字体不清晰问题
- iOS开发学习之Quartz2D绘图
- 【Leetcode】Validate Binary Search Tree
- 生活随笔:病人(2)
- 《Android开发艺术探索》读书笔记 (2) 第2章 IPC机制
- Codeforces 621 D Rat Kwesh and Cheese
- [android]_[handler的简单使用]
- 业界资讯:swift的API正在转变
- 集合 TreeSet HashMap
- 整数划分问题经典解法(有用)
- CF#341-B-Wet Shark and Bishops-水题
- 补充:this的应用
- 【杭电】[2024]C语言合法标识符
- 记录Android-Studio遇到的各种坑