Cat

时间： 1ms 内存：128M

描述：

In strong winds, sailboats tend to heel leeward (tilt away from the wind) like the one in the picture. Heeling is undesirable for at least two reasons. First, the effective sail area is reduced, as the effective height of the sail is multiplied by the cosine of the angle. Reduced sail area implies reduced speed. Second, the boat may heel to the point that its centre of gravity ceases to be above the hull, causing the boat to capsize.

To mitigate these problems, catamarans like the one shown split the hull into two pieces (the port and starboard hulls). This design increases the effective width of the boat. Increased width decreases the vertical mechanical advantage of the sail, thus reducing heeling. Increased width also increases the angle of heeling that can be tolerated before the boat capsizes.

Heeling can also be mitigated by having the crew sit or stand on, or even hike out beyond, the windward hull. If you look carefully at the picture you can see the two person crew hiking to windward.

At some wind velocity, even these measures are insufficient to keep the boat upright. A skipper's only choice (other than to capsize) is to let out the sail, which reduces its effective horizontal dimension much as heeling reduces its vertical dimension. As with heeling, this action causes loss of speed. If the boat heels sufficiently, it may not even be possible to let out the sail, as its outer corner may be obstructed by the surface of the water!

Reefing is a mechanism for reducing the sail's area. Roller reefing involves wrapping the sail around the boom (much like a window blind) so as to reduce its height. With sufficient reefing, the heeling can be controlled in almost any wind.

But reefing involves reduced speed, so our skipper has elected yet another approach. She has decided to beach the boat and pick up some rocks to use as ballast. Ballast is just dead weight added to hull, which tends to counteract heeling. It slows the boat a bit (as it rides lower in the water) but not nearly so much as reducing sail area.

Given

nrocks, you are to compute how to divide them between the port and starboard hulls so that the weight of rocks in each hull is nearly equal.Input contains several test cases. Each test case begins with 1 <

n≤ 100; the number of rocks to be added as ballast. Consider the rocks to be numbered 1 throughn.nlines follow; theith line gives the weight in kg of theith rock - a positive real number not greater than 100. A line containing 0 follows the last test case.For each test case, output a single line giving the numbers of the rocks that should be loaded as ballast into the starboard hull. Assume that the other rocks will be loaded into the port hull. The total weight of ballast in the port hull should not differ from that in the starboard hull by more than 2%. If there are many solutions, any one will do. There will always be a solution; indeed, there will always be a solution that balances within 1%, but you aren't required to find it.

输入：

Please Input Input Here

输出：

Please Input Output Here

示例输入：

```
5
10.0
50.0
90.0
38.0
7.1
0
```

示例输出：

```
3 5
```

提示：

参考答案（内存最优[960]）：

```
#include <stdio.h>
#include <memory.h>
double sum,r[100];
int i,j,k,m,n, R[100], prev[20001], who[20001];
char tmp[1000];
main(){
while (1 == scanf("%d",&n) && n) {
for (i=0;i<n;i++) scanf("%lf",&r[i]);
for (i=sum=0;i<n;i++) sum += r[i];
for (i=0;i<n;i++) R[i] = r[i] * 20000/sum;
memset(who,0,sizeof(who));
memset(prev,0,sizeof(prev));
who[0] = -1;
for (i=0;i<n;i++) {
for (j=10000;j>=0;j--) {
if (!who[j]) continue;
if (who[j+R[i]]) continue;
who[j+R[i]] = i+1;
prev[j+R[i]] = j;
}
}
for (i=10000;!who[i];i--);
while (i) {
printf("%d ", who[i]);
i = prev[i];
}
printf("\n");
}
if (n != 0) printf("missing end delimeter\n");
}
/**************************************************************
Problem: 1217
User: zhblue
Language: C++
Result: Compile Error
****************************************************************/
```

参考答案（时间最优[332]）：

```
#include <stdio.h>
#include <memory.h>
double sum,r[100];
int i,j,k,m,n, R[100], prev[20001], who[20001];
char tmp[1000];
main(){
while (1 == scanf("%d",&n) && n) {
for (i=0;i<n;i++) scanf("%lf",&r[i]);
for (i=sum=0;i<n;i++) sum += r[i];
for (i=0;i<n;i++) R[i] = r[i] * 20000/sum;
memset(who,0,sizeof(who));
memset(prev,0,sizeof(prev));
who[0] = -1;
for (i=0;i<n;i++) {
for (j=10000;j>=0;j--) {
if (!who[j]) continue;
if (who[j+R[i]]) continue;
who[j+R[i]] = i+1;
prev[j+R[i]] = j;
}
}
for (i=10000;!who[i];i--);
while (i) {
printf("%d ", who[i]);
i = prev[i];
}
printf("\n");
}
if (n != 0) printf("missing end delimeter\n");
}
/**************************************************************
Problem: 1217
User: zhblue
Language: C++
Result: Compile Error
****************************************************************/
```

题目和答案均来自于互联网，仅供参考，如有问题请联系管理员修改或删除。