【暴力,STL,水】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.

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的使用。详细的介绍自行百度。
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 const int INF = 0x7fffffff;
 8 int weight[10];
 9 double solve()
10 {
11     int sum_Mv = weight[0]*(-1) + weight[1]*0 + weight[2]*1 + weight[3]*(-1) + weight[4]*1 + weight[5]*(-1) + weight[6]*0 + weight[7]*1;
12     int sum_Mh = weight[0]*(-1) + weight[1]*(-1) + weight[2]*(-1) + weight[3]*0 + weight[4]*0 + weight[5]*1 + weight[6]*1 + weight[7]*1;
13     return sqrt(sum_Mv*sum_Mv+sum_Mh*sum_Mh);
14 }
15
16 int main()
17 {
18
19     while(1)
20     {
21         bool ok = false;
22         for(int i = 0; i < 8; i++)
23         {
24             scanf("%d", &weight[i]);
25             if(weight[i]) ok = true;
26         }
27         if(!ok) break;
28
29         sort(weight, weight+8);
30         double ans = INF;
31         while(next_permutation(weight, weight+8))
32         {
33             ans = min(ans, solve());
34         }
35         printf("%.3lf\n", ans);
36     }
37     return 0;
38 }
时间: 2024-08-29 01:07:32

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

HDU 5280 Senior&#39;s Array (暴力,水)

题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define pii pair<int,int> 4 #define INF 0x7f7f7f7f 5 using namespace std; 6 const int N=2000; 7 int a[N]

CodeForces 589I Lottery (暴力,水题)

题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma

[bzoj 1208]STL水过

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1208 看网上的题解都用的手写数据结构--然而直接用set的lower_bound就水过去了-- #include<bits/stdc++.h> using namespace std; const int md=1000000; set<int> pet,people; int main() { int n; scanf("%d",&n); in

CodeForces 711B Chris and Magic Square (暴力,水题)

题意:给定n*n个矩阵,其中只有一个格子是0,让你填上一个数,使得所有的行列的对角线的和都相等. 析:首先n为1,就随便填,然后就是除了0这一行或者这一列,那么一定有其他的行列是完整的,所以,先把其他的算出来,然后再作差就算这个数了, 然后再去验证其他的对不对就好了.除了n为1,其他的都是唯一解应该.或者没有. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i

UVA 11991 Easy Problem from Rujia Liu? 简单STL

题目链接: UVA, 你懂的 题目描述: 给出一串数, 求第几次出现的数字几? 解题思路: 北交集训STL水题 代码: #include <iostream> #include <cstdio> #include <cstring> #include <map> using namespace std; const int MAXN = 1e5 + 7; map<int, int> cnt; map<pair<int, int>

hdu 1022 Train Problem I(栈的应用+STL)

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20521    Accepted Submission(s): 7712 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays

zzuli1985(dp/水dfs郑轻比赛)

再一次感受到dp的威力 1985: 即将到来的新生赛 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 112  Solved: 28 SubmitStatusWeb Board Description 新生赛马上就要到来了.为了举办这次比赛,学校也是大费苦心.由于时间紧迫,要准备的事情太多,人员安排也是很伤脑子.身为一个聪明的acmer,这点小事对你来说应该是So easy! 距离新生赛开始剩余100个小时,现在还剩余m项任务.每个任务都有开始时间,

暴力+降复杂度 BestCoder Round #39 1002 Mutiple

题目传送门 1 /* 2 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 3 若没有,默认加0,nlogn复杂度: 4 我用暴力竟然水过去了:) 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 using namespace std;

HLJU周赛5解题报告

Problem A: 求第K大数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 81  Solved: 32 [Submit][Status][Web Board] [Edit] [TestData] Description 一天,喜欢看电影的DoubleQ 和 XXZ 来到一个神奇的电影院,这个电影院可以同时放映n部电影,每部电影都有相应的票价xi,面对着杀破狼2,侏罗纪世界,少年班等等好看的电影,他们最后商量,看票价第K大的电影,但是由于电影