【17.00%】【codeforces 621D】Rat Kwesh and Cheese

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.

Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options:

a1 = xyz;
a2 = xzy;
a3 = (xy)z;
a4 = (xz)y;
a5 = yxz;
a6 = yzx;
a7 = (yx)z;
a8 = (yz)x;
a9 = zxy;
a10 = zyx;
a11 = (zx)y;
a12 = (zy)x.
Let m be the maximum of all the ai, and c be the smallest index (from 1 to 12) such that ac = m. Rat’s goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that ac.

Input
The only line of the input contains three space-separated real numbers x, y and z (0.1 ≤ x, y, z ≤ 200.0). Each of x, y and z is given with exactly one digit after the decimal point.

Output
Find the maximum value of expression among xyz, xzy, (xy)z, (xz)y, yxz, yzx, (yx)z, (yz)x, zxy, zyx, (zx)y, (zy)x and print the corresponding expression. If there are many maximums, print the one that comes first in the list.

xyz should be outputted as x^y^z (without brackets), and (xy)z should be outputted as (x^y)^z (quotes for clarity).

Examples
input
1.1 3.4 2.5
output
z^y^x
input
2.0 2.0 2.0
output
x^y^z
input
1.9 1.8 1.7
output
(x^y)^z

【题解】

200^200^200是无法接受的;
考虑取log之后再比较;->高中老师教过的方法我怎么就忘了呢。
然后200^200->1e460左右;但是在long double 前这都不算啥;
long double 最高到10^4932;
所以放心用吧;
另外如果取两次对数会失精度;
一大波WA在等着你;
取对数的时候加加减减小心点;
(或者取两次对数,给的x,y,z比较小的时候直接算.否则取两次对数?->考虑x小于1的时候直接乘,但是0.1 200 200 这样的数据没办法直接算,而两次log精度又不够,所以long double+只取一次log是最好的选择;)

#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long

using namespace std;

//const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);

long double x,y,z;
long double ans[15];

void input_LL(LL &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t)) t = getchar();
    LL sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}

void input_int(int &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t)) t = getchar();
    int sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    cin>>x>>y>>z;
    ans[1] = pow(y,z)*log(x);
    ans[2] = pow(z,y)*log(x);
    ans[3] = z*y*log(x);
    ans[4] = ans[3];
    ans[5] = pow(x,z)*log(y);
    ans[6] = pow(z,x)*log(y);
    ans[7] = x*z*log(y);
    ans[8] = ans[7];
    ans[9] = pow(x,y)*log(z);
    ans[10] = pow(y,x)*log(z);
    ans[11] = x*y*log(z);
    ans[12] = ans[11];
    int j = 1;
    for (int i = 2;i <= 12;i++)
        if (ans[j]<ans[i])
            j = i;
    switch (j)
    {
    case 1:
        puts("x^y^z");
        break;
    case 2:
        puts("x^z^y");
        break;
    case 3:
        puts("(x^y)^z");
        break;
    case 4:
        puts("(x^z)^y");
        break;
    case 5:
        puts("y^x^z");
        break;
    case 6:
        puts("y^z^x");
        break;
    case 7:
        puts("(y^x)^z");
        break;
    case 8:
        puts("(y^z)^x");
        break;
    case 9:
        puts("z^x^y");
        break;
    case 10:
        puts("z^y^x");
        break;
    case 11:
        puts("(z^x)^y");
        break;
    case 12:
        puts("(z^y)^x");
        break;
    }
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7632110.html

CodeForces - 616D是一个关于找到一个序列中最长的第k好子段的起始位置和结束位置的问题。给定一个长度为n的序列和一个整数k,需要找到一个子段,该子段中不超过k个不同的数字。题目要求输出这个序列最长的第k好子段的起始位置和终止位置。 解决这个问题的方法有两种。第一种方法是使用尺取算法,通过维护一个滑动窗口来记录\[l,r\]中不同数的个数。每次如果这个数小于k,就将r向右移动一位;如果已经大于k,则将l向右移动一位,直到个数不大于k。每次更新完r之后,判断r-l+1是否比已有答案更优来更新答案。这种方法的时间复杂度为O(n)。 第二种方法是使用枚举r和双指针的方法。通过维护一个最小的l,满足\[l,r\]最多只有k种数。使用一个map来判断数的种类。遍历序列,如果当前数字在map中不存在,则将种类数sum加一;如果sum大于k,则将l向右移动一位,直到sum不大于k。每次更新完r之后,判断i-l+1是否大于等于y-x+1来更新答案。这种方法的时间复杂度为O(n)。 以上是两种解决CodeForces - 616D问题的方法。具体的代码实现可以参考引用\[1\]和引用\[2\]中的代码。 #### 引用[.reference_title] - *1* [CodeForces 616 D. Longest k-Good Segment(尺取)](https://blog.csdn.net/V5ZSQ/article/details/50750827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces616 D. Longest k-Good Segment(双指针+map)](https://blog.csdn.net/weixin_44178736/article/details/114328999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值