zoukankan      html  css  js  c++  java
  • POJ 1862 Stripies

    Stripies
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 10373   Accepted: 5017

    Description

    Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply for an international patent). The stripies are transparent amorphous amebiform creatures that live in flat colonies in a jelly-like nutrient medium. Most of the time the stripies are moving. When two of them collide a new stripie appears instead of them. Long observations made by our scientists enabled them to establish that the weight of the new stripie isn't equal to the sum of weights of two disappeared stripies that collided; nevertheless, they soon learned that when two stripies of weights m1 and m2 collide the weight of resulting stripie equals to 2*sqrt(m1*m2). Our chemical biologists are very anxious to know to what limits can decrease the total weight of a given colony of stripies.  You are to write a program that will help them to answer this question. You may assume that 3 or more stipies never collide together. 

    Input

    The first line of the input contains one integer N (1 <= N <= 100) - the number of stripies in a colony. Each of next N lines contains one integer ranging from 1 to 10000 - the weight of the corresponding stripie.

    Output

    The output must contain one line with the minimal possible total weight of colony with the accuracy of three decimal digits after the point.

    Sample Input

    3
    72
    30
    50
    

    Sample Output

    120.000

    有一些单细胞生物,每两个可以相碰撞形成一个新的,新的生物重量为2*sqrt(m1*m2)

    给定一些单细胞生物,求一种最佳的方式,使它们经过碰撞后最终剩下的一个单细胞生物的重量最小。

    现假设重量为b和c的两个单细胞生物都想与a碰撞,那么我们应该让哪个先与a碰撞呢

    若b先,则最终重量为2*sqrt(c*2*sqrt(a*b))

    若c先,则最终重量为2*sqrt(b*2*sqrt(a*c))

    假设要让b先,则就2*sqrt(c*2*sqrt(a*b))<=2*sqrt(b*2*sqrt(a*c)),化简得到c<=b。

    由此我们知道要从重量大的先碰撞,重量小的后碰撞。

     

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 
     6 using namespace std;
     7 
     8 int n;
     9 int num[110];
    10 
    11 bool cmp(int a,int b)
    12 {
    13     return a>=b;
    14 }
    15 
    16 int main()
    17 {
    18     while(cin>>n)
    19     {
    20         for(int i=0;i<n;i++)
    21             scanf("%d",&num[i]);
    22         if(n==1)
    23         {
    24             printf("%.3lf
    ",(double)num[0]);
    25             continue;
    26         }
    27         sort(num,num+n,cmp);
    28         double ans=2*sqrt((double)num[0]*num[1]);
    29         for(int i=2;i<n;i++)
    30             ans=2*sqrt(ans*num[i]);
    31         printf("%.3lf
    ",ans);
    32     }
    33 
    34     return 0;
    35 }
    [C++]
  • 相关阅读:
    socket是什么
    0,1,2 代表标准输入、标准输出、标准错误
    认识程序的执行:从高级语言到二进制,以java为例
    97 条 Linux 运维工程师常用命令总结[转]
    rsync 参数配置说明[转]
    shell 脚本学习之内部变量
    ansible 入门学习(一)
    python 管理多版本之pyenv
    CentOS6 克 隆
    yum 本地仓库搭建
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3246545.html
Copyright © 2011-2022 走看看