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. Hibernate之继承映射

    1. Hibernate支持三种继承映射策略: –使用 subclass进行映射:将域模型中的每一个实体对象映射到一个独立的表中,也就是说不用在关系数据模型中考虑域模型中的继承关系和多态. –使用 j ...

  2. POJ 3177 Redundant Paths(强连通分量)

    题目链接:http://poj.org/problem?id=3177 题目大意是一个无向图给你n个点m条边,让你求出最少加多少条边 可以让任意两个点相通两条及以上的路线(每条路线点可以重复,但是每条 ...

  3. Lua学习笔记(六):协程

    多线程和协程 多线程是抢占式多任务(preemptive multitasking),每个子线程由操作系统来决定何时执行,由于执行时间不可预知所以多线程需要使用同步技术来避免某些问题.在单核计算机中, ...

  4. javascript:history.go(-1);

    history是你浏览过的网页的url(简单的说就是网址)的集合,也就是你的浏览器里的那个历史记录.它在js里是一个内置对象,就跟document一样,它有自己的方法,go就是其中一个. 这个方法的参 ...

  5. 对同一元素设置overflow-x:hidden,overflow-y:visible;属性值不生效

    作者:孙志勇 微博 日期:2016年12月5日 一.时效性 所有信息都具有时效性.文章的价值,往往跟时间有很大关联.特别是技术类文章,请注意本文创建时间,如果本文过于久远,请读者酌情考量,莫要浪费时间 ...

  6. 多线程访问winform控件出现异常的解决方法

    一.  多线程访问winform控件出现异常的解决方法 1.  问题描述<1> 如果创建某控件的线程之外的其他线程试图调用该控件,则会引发一个 InvalidOperationExcept ...

  7. MDF文件数据恢复

  8. 【M2】最好使用C++转型操作符

    1.C语言中的转型操作符有两个问题: a.是个通用的转换操作符,也就是说,可以从一个类型转换到其他类型.通用必定是低效率和冗余的,因为要考虑很多情况. b.在代码中,难以辨认出哪些是类型转换. 2.C ...

  9. 微信公众平台Token验证失败的解决办法

    微信公众平台Token验证失败的解决办法 1.可查看url和token是否正确 2.查看服务器端口是否为80端口 3.你可以通过记录log日志来判断是否接受到微信提交过来的信息 1.$fp=fopen ...

  10. 怎样拷贝整个目录并且忽略部分文件及目录(包括windows)

    http://www.dewen.org/q/2150 rsync -a --exclude dir1 --exclude dir2 ... source target