Codeforces #341 D. Rat Kwesh and Cheese 浮点数处理技巧 好题
来源:互联网 发布:淘宝上的atinis可靠吗 编辑:程序博客网 时间:2024/06/07 15:55
题目
题目链接:http://codeforces.com/problemset/problem/621/D
题目来源:cf#341
简要题意:给定公式求值最大中下标最小的公式。
题解
这题需要对于浮点数有比较高深的理解。首先复习一下浮点数的范围。
考虑取一个对数的话,值就算用double也是不够的,要用long double。
然后将对应的公式取对数就行了。取pow的时候需要使用powl,这是long double版本的pow函数。
由于考察的知识比较偏门,所以说这道D过的人比E还要少,不过A了它的确可以学到新姿势。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define sz(x) ((int)(x).size())#define fi first#define se secondusing namespace std;typedef long long LL;typedef vector<int> VI;typedef pair<int,int> PII;LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}// headchar out[12][15] = { "x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"};long double a[15];int main() { double x, y, z; scanf("%lf%lf%lf", &x, &y, &z); long double logx = log(x); long double logy = log(y); long double logz = log(z); a[0] = logx * powl(y, z); a[1] = logx * powl(z, y); a[2] = logx * y * z; a[3] = -1; a[4] = logy * powl(x, z); a[5] = logy * powl(z, x); a[6] = logy * x * z; a[7] = -1; a[8] = logz * powl(x, y); a[9] = logz * powl(y, x); a[10] = logz * x * y; a[11] = -1; long double ans = a[0]; int ind = 0; for (int i = 1; i < 12; i++) { if (!fabs(ans-a[i]) < 1e-8 && a[i] > ans) { ans = a[i]; ind = i; } } printf("%s\n", out[ind]); return 0;}
0 0
- Codeforces #341 D. Rat Kwesh and Cheese 浮点数处理技巧 好题
- 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
- 【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) Editorial D - Rat Kwesh and Cheese(数学,高精度)
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese (pow,复数
- codeforce341 D题 Rat Kwesh and Cheese(复数)
- CF621D - Rat Kwesh and Cheese
- CodeForces - 366D Dima and Trap Graph (并查集&技巧)好题
- Codeforces Round #442 (Div. 2)-广搜&剪枝&技巧&好题-D. Olya and Energy Drinks
- codeforces #309 D D. Nudist Beach(浮点数二分+bfs)
- Codeforces 361D Levko and Array【二分+dp】好题!
- Codeforces 586D Phillip and Trains【思维+Bfs】好题~!
- 微信支付第一次成功 后来就一直不行
- First Day,Time will say!
- 单链表 尾插法
- hdu1073
- 用qml开发的手机助手软件
- Codeforces #341 D. Rat Kwesh and Cheese 浮点数处理技巧 好题
- 象棋棋子类包括棋子属性及走法
- IOS多线程(待完整)
- Oracle调用Java外部存储过程
- Softmax
- 最好的markdown编辑器
- 里氏代换原则
- 关于web.xml中的<welcome-file-list>中的默认首页文件
- 游戏中的三角学——Sprite Kit 和 Swift 教程(1)