Round A APAC Test 2016 Problem B. gCube

Problem B. gCube

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
8 points
Large input
16 points

Problem

Googlers are very interested in cubes, but they are bored with normal three-dimensional cubes and also want to think about other kinds of cubes! A "D-dimensional cube" has D dimensions, all of equal length. (D may be any positive integer; for example, a 1-dimensional cube is a line segment, and a 2-dimensional cube is a square, and a 4-dimensional cube is a hypercube.) A "D-dimensional cuboid" has D dimensions, but they might not all have the same lengths.

Suppose we have an N-dimensional cuboid. The N dimensions are numbered in order (0, 1, 2, ..., N - 1), and each dimension has a certain length. We want to solve many subproblems of this type:

1. Take all consecutive dimensions between the Li-th dimension and Ri-th dimension, inclusive.

2. Use those dimensions to form a D-dimensional cuboid, where D = Ri - Li + 1. (For example, if Li = 3 and Ri = 6, we would form a 4-dimensional cuboid using the 3rd, 4th, 5th, and 6th dimensions of our N-dimensional cuboid.)

3. Reshape it into a D-dimensional cube that has exactly the same volume as that D-dimensional cuboid, and find the edge length of that cube.

Each test case will have M subproblems like this, all of which use the same original N-dimensional cuboid.

Input

The first line of the input gives the number of test cases, TT test cases follow.

Each test case begins with two integers N and MN is the number of dimensions and Mis the number of queries. Then there is one line with N positive integers ai, which are the lengths of the dimensions, in order. Then, M lines follow. In the ith line, there are two integers Li and Ri, which give the range of dimensions to use for the ith subproblem.

Output

For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). After that, output M lines, where the ith line has the edge length for the ith subproblem. An edge length will be considered correct if it is within an absolute error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of real numbers we accept.

Limits

1 ≤ T ≤ 100.
1 ≤ ai ≤ 109
0 ≤ Li ≤ Ri < N.

Small dataset

1 ≤ N ≤ 10.
1 ≤ M ≤ 10.

Large dataset

1 ≤ N ≤ 1000.
1 ≤ M ≤ 100.

Sample


Input 
 

Output 
 
2
2 2
1 4
0 0
0 1
3 2
1 2 3
0 1
1 2


Case #1:
1.000000000
2.000000000
Case #2:
1.414213562
2.449489743

题意,其实就是很l r区间的数乘积开根号就可以了。

#define N 1005
#define M 100005
#define maxn 205
#define MOD 1000000000000000007
int n,T,m,pri[N],s,e,d;
int main()
{
    freopen("B-large.in", "r", stdin);
    freopen("B-large.out", "w", stdout);
     while(S(T)!=EOF)
    {
        For(ta,1,T+1){
            printf("Case #%d:\n",ta);
            S2(n,m);
            FI(n) S(pri[i]);
            FI(m){
                S2(s,e);
                double ans = 1.0;
                d = e - s + 1;
                For(i,s,e + 1){
                    ans *=  pow( (double)pri[i],1.0/(double)d);
                }
                printf("%.9f\n",ans);
            }
        }

    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值