Poison time limit:500 MS Memory limit:32768 K Total submit:148 (all users) total accepted:103 (users) rating:special JUDG E:no Description existing n bottles of poison, 1th bottle of poison toxicity of 1, the first bottle of poison than the first i-1 bottle poison Increased toxicity (((i-1) *k)%m), will be the poison of the first bottle I do VI.
You can mix any two bottles of poison. If the poison of bottle I and Bottle J is mixed, the toxicity of the mixed poison is 2*sqrt (VI*VJ). (Sqrt said).
Merge to the end, there will be only one bottle of poison left. What is the minimum toxicity of the last remaining poison? Input the first line of a number T, indicating that there is a T-group data.
There is only one row for each set of data, containing three numbers n, K, M.
(n <= 1000000)
(K, M <= 1000) output The minimum toxicity of a residual poison for each set of data. Retains three decimal places. Sample Input 2
2 2 1000
3 2 1000 Sample Output 3.464
6.055
To get the smallest number, it must be a mixture of two adjacent poisons, so. Just sort it.
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
Double a[1000005];
int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
int n,k,m;
scanf ("%d%d%d", &n,&k,&m);
a[1]=1.0;
for (int i=2;i<=n;i++)
{
a[i]=a[i-1]+ ((i-1) *k)%m);
Sort (a+1,a+1+n);
for (int i=n-1;i>=1;i--)
{
a[n]=2.0*sqrt (a[n]*a[i]);
}
printf ("%.3lf\n", A[n]);
return 0;
}