Hust OJ 2235 Poison (water title)

Source: Internet
Author: User
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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.