UVA 1523 - Helicopter(暴力枚举)

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.

\epsfbox{p2032.eps}

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 =  $\displaystyle \sqrt{​{(\sum^{8}_{i=1}Mv_{i})^{2}+(\sum^{8}_{i=1}Mh_{i})^{2}}}$

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

题意:给定8个乘客质量,问怎么安排乘客位置使得飞机尽可能平衡。

思路:n为8,直接暴力全排序。求出最小M值即可。

代码:

#include <stdio.h>
#include <math.h>
#include <algorithm>
#define min(a,b) (a)<(b)?(a):(b)
#define INF 0x3f3f3f3f
using namespace std;

int a[8];

double cal() {
	double v = a[0] + a[3] + a[5] - a[2] - a[4] - a[7];
	double h = a[0] + a[1] + a[2] - a[5] - a[6] - a[7];
	double ans = sqrt(v * v + h * h);
	return ans;
}

double solve() {
	sort(a, a + 8);
	double ans = cal();
	while (next_permutation(a, a + 8)) {
		ans = min(ans, cal());
	}
	return ans;
}

int main() {
	while (1) {
		int sum = 0;
		for (int i = 0; i < 8; i ++) {
			scanf("%d", &a[i]);
			sum += a[i];
		}
		if (sum == 0) break;
		printf("%.3lf\n", solve());
	}
	return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值