Since ancient time, people have been dreaming of flying in the sky. Eventually, the dream was realized in the 20th century. Nowadays, the airplane becomes a useful vehicle that is used frequently in our daily life.

But before the dream came true, a large number of people had tried to design the aircrafts. One of those aircrafts, which is called ``helicopter" in modern time, can be traced back to the blueprint of the aircraft designed by Leonardo da Vinci. But the helicopter was not effective enough till this century.

Since the helicopter rises through the updraft generated by the airscrew, it is very important for it to keep balance. Even for the late-model helicopters, the loads are required to be distributed evenly, so that the center of gravity of the helicopter lies just underneath the airscrew. It is one of the most important requirements for it in flight.

Now, you are requested by an airline company to write a program for a passenger transport helicopter. The program may arrange a seat for each passenger automatically so that the center of gravity of the helicopter should be located underneath the airscrew as dose as possible. The seats in the helicopter and the airscrew are designed as the figure below.

You may assume the distance of the adjoining seats is 1 unit, and the airscrew occupies a seat. A seat along with a passenger on it will generate a transverse mome nt and a longitudinal moment. The transverse moment,Mvi, is the weight of a passenger on the seat multiplied by the transverse distance from the seat to the airscrew. The longitudinal moment, Mhi, is the weight of a passenger on the seat multiplied by the longitudinal distance. If the transverse moments generated by the passengers on the left are assumed to be positive, the moments by the passengers on the right will be negative. Also, if the longitudinal moments generated by the passengers in front are assumed to be positive, the moments by the passengers on the back will be negative. That is, the moments may counteract with each other. You may use the formula below to figure out the composition of moments.

M = 

If M = 0, the center of gravity of the helicopter lies just underneath the airscrew.

You are required to arrange the seats of 8 passengers according to their weights to locate the center of gravity underneath the airscrew as far as possible. That is, the value of M should be minimum.

Input

The input file may contain several test cases. Each test case consists of eight integers in lines, which represent the weights of those passengers. The end of input is signified by the test case in which the weights are all 0. And this test case should not be processed.

Output

The output for each test case should include a line contains a real number which tells the composition of moments, M, in the optimal arrangement. The output of the composition of moments should be accurate to 3 decimal places. And you should not print any more white spaces or blank lines in the output.

Sample Input

1 2 3 4 5 6 7 8
0 0 0 0 0 0 0 0

Sampple Output

0.000

题意:一架灰机,八个座位,坐着八个人,每人一个重量,要求使灰机平衡,即使上面的公式求得的M尽量小。式中Mvi指第i个人的重量乘以他的相对水平位移,Mhi指第i个人的重量乘以他的相对垂直位移;至于所谓的相对水平垂直位移,比如左上角的人,相对水平位移是-1,相对垂直位移是-1,右上角相对水平位移是1,相对垂直位移是-1,这样明白了吧。
因为只有8个人,数据很小,即使全排列8!也不会很大。所以可以直接暴力计算。
这个题唯一让自己觉得有点价值的就是STL中next_permutation的使用。详细的介绍自行百度。
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x7fffffff;
int weight[];
double solve()
{
int sum_Mv = weight[]*(-) + weight[]* + weight[]* + weight[]*(-) + weight[]* + weight[]*(-) + weight[]* + weight[]*;
int sum_Mh = weight[]*(-) + weight[]*(-) + weight[]*(-) + weight[]* + weight[]* + weight[]* + weight[]* + weight[]*;
return sqrt(sum_Mv*sum_Mv+sum_Mh*sum_Mh);
} int main()
{ while()
{
bool ok = false;
for(int i = ; i < ; i++)
{
scanf("%d", &weight[i]);
if(weight[i]) ok = true;
}
if(!ok) break; sort(weight, weight+);
double ans = INF;
while(next_permutation(weight, weight+))
{
ans = min(ans, solve());
}
printf("%.3lf\n", ans);
}
return ;
}

【暴力,STL,水】UVa 1523 - Helicopter的更多相关文章

  1. POJ-2773 Happy 2006,暴力2700ms+水过!

                                                         Happy 2006 这个题很可能会超时的,但我几乎暴力的方法2700ms+过了,可能是后台水 ...

  2. hdu4585 STL水题

    题意:       成立少林寺,刚开始有一个大师,id是1,攻击力是10E,现在陆续来人,每个人有自己的id,和自己的攻击力,但是每一个新来的要和之前的和尚pk,他必须选择和他攻击力差值最小的那个,如 ...

  3. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  4. 【暴力模拟】UVA 1594 - Ducci Sequence

    想麻烦了.这题真的那么水啊..直接暴力模拟,1000次(看了网上的200次就能A)后判断是否全为0,否则就是LOOP: #include <iostream> #include <s ...

  5. Codeforces 842A Kirill And The Game【暴力,水】

    A. Kirill And The Game time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  6. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL

    What Kind of Friends Are You? Time Limit: 1 Second      Memory Limit: 65536 KB Japari Park is a larg ...

  7. [bzoj 1208]STL水过

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1208 看网上的题解都用的手写数据结构……然而直接用set的lower_bound就水过去了 ...

  8. Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...

  9. Codeforces 106D Treasure Island 预处理前缀+暴力(水

    主题链接:点击打开链接 意甲冠军: 特定n*m矩阵 # 是墙 . 和字母是平地 最多有26个字母(不反复出现) 以下k个指令. 每一个指令代表移动的方向和步数. 若以某个字母为起点,依次运行全部的指令 ...

随机推荐

  1. Spring Object/XML mapping example

    In this tutorial, we will extend last Maven + Spring hello world example by adding JDBC support, to ...

  2. My97DatePicker的calendar.js的反混淆

    eval(string)函数 <script> eval(function(p, a, c, k, e, d) { p = 'function p(){console.log(" ...

  3. Altium Desiger自定义BOM导出格式

    用Excel做一个xx.xlt的2003的模版文件,如名为:AltiumDesiger PCB BOM Template.xlt 将AltiumDesiger PCB BOM Template.xlt ...

  4. Educational Codeforces Round 1(C. Nearest vectors)

    题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...

  5. POJ 1679 The Unique MST (次小生成树)

    题目链接:http://poj.org/problem?id=1679 有t组数据,给你n个点,m条边,求是否存在相同权值的最小生成树(次小生成树的权值大小等于最小生成树). 先求出最小生成树的大小, ...

  6. Serializable 序列化为文件

    package test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...

  7. session cookie原理及应用

    一.术语session在我的经验里,session这个词被滥用的程度大概仅次于transaction,更加有趣的是transaction与session在某些语境下的含义是相同的. session,中 ...

  8. win7硬盘安装Ubuntu12.04 64位时显示Error 15: File not found.

    安装Ubuntu12.04 -64位时,用EasyBCD建好引导文件重启电脑后出现如下错误: Error 15: File not found 原因一个是安装文件所在盘符不对,另一个是文件名.Ubun ...

  9. eclipse中异常的快捷键

    选中你要try的代码,alt+shift+z 就会弹出一个菜单,里面有个try 选项

  10. The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...