Problem B. gCube Google APAC 2016 University Test Round A

这一题的数据量直接暴力N^2枚举即可。a[L]*a[L+1]*...*a[R]=x^D。

等式左边直接相乘可能会溢出,所以求1/D次方,再相乘。a[L]^(1/D)*a[L+1]^(1/D)*...*a[R]^(1/D)=x。

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

//2016 Round A Problem B. gCube
int T;
const int maxn=1010;
const double eps=1e-9;
int a[maxn];
int L;
int R;
int N;
int M;
int main()
{
    freopen("B-large-practice.in","r",stdin);
//    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&T);
    for(int ca=1;ca<=T;ca++)
    {
        printf("Case #%d:\n",ca);
        memset(a,0,sizeof(a));
        scanf("%d %d",&N,&M);
        for(int i=0;i<N;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=0;i<M;i++)
        {
            scanf("%d %d",&L,&R);
            int D=R-L+1;
            double ans=1;
            for(int x=L;x<=R;x++)
            {
                ans*=pow(1.0*a[x],1.0/D);
                //cout<<ans<<endl;
            }
            printf("%.9f\n",ans);
        }

    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值