POJ 1853 knapsack problem

Source: Internet
Author: User

Cat
Time Limit: 1500MS Memory Limit: 30000K
Total Submissions: 1580 Accepted: 401 Special Judge

Description

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 and both reasons. First, the effective sail area is reduced, as the effective height of the sail was multiplied by the cosine of the angle. Reduced sail area implies reduced speed. Second, the boat may heel to the point, its centre of gravity ceases to being above the hull, causing the boat to capsize .
To mitigate these problems, catamarans as the one shown split the hull into both 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 the can be tolerated before the boat capsizes.

Heeling can also is mitigated by has 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 crew hiking to windward.

At some wind velocity, even these measures is insufficient to keep the boat upright. A skipper ' s only choice (and than to capsize) are to let out the sail, which reduces its effective horizontal dimension m Uch as heeling reduces its vertical dimension. As with heeling, this action causes loss for speed. If The boat heels sufficiently, it may is not even is possible to let out of the sail, as its outer corner could 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) as-to-reduce its height. With sufficient reefing, the heeling can is controlled in almost all wind.

But reefing involves reduced speed, so we 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) and not nearly so much as reducing sail area.

Given n Rocks, you is to compute what to divide them between the port and starboard hulls so that the weight of rocks in E Ach hull is nearly equal.

Input

Input contains several test cases. Each test case begins with 1 < n <= 100; The number of rocks to is added as ballast. Consider the rocks to be numbered 1 through N. n lines follow; The ith line gives the weight in kg of the ith rock-a positive real number is not greater than 100. A line containing 0 follows the last test case.

Output

For each test case, output a single line giving the numbers of the rocks that should is loaded as ballast into the Starboa Rd Hull. Assume the other rocks'll be loaded into the port hull. The total weight of ballast in the port hull should not differ from this in the starboard hull by more than 2%. If There is many solutions, any one would do. There'll always be a solution; Indeed, there'll always be a solution that balances within 1, but you're aren ' t required to find it.

Sample Input

510.050.090.038.07.10

Sample Output

3 5

Source

Waterloo Local 2004.09.19

Test instructions: Given a certain number of items and the quality of goods, asked whether the goods can be divided into two piles, and then the difference between 2%;

Problem-solving ideas: Because the topic is related to the decimal, so it is not good to do with DP , you need to multiply the decimal number by one count it into an integer backpack, in this problem to find the quality of each object to the total mass ratio and then multiplied by the sum, and then a DP ;

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <stack>7 using namespacestd;8 Const intmaxn=22010;9 BOOLDP[MAXN];Ten intN; One Doubleinput[107]; A intnum[107],ROAD[MAXN]; - Doublesum; -stack<int>s; the voidInit () - { -Memset (DP,0,sizeof(DP)); -memset (NUM,0,sizeof(num)); +sum=0; -      while(!s.empty ()) S.pop (); + } A voidDP () at { -dp[0]=1; -      for(intI=1; i<=n;i++) -     { -          for(intj=10000; j>=0; j--) -         { in             if(Dp[j]&&!dp[j+num[i]]) dp[j+num[i]]=1, road[j+num[i]]=i; -            to         } +     } - } the intMain () * { $  //freopen ("In.txt", "R", stdin);Panax Notoginseng      while(1){ -scanf"%d",&n); the         if(!n) Break; + init (); A         DoubleF; the          for(intI=1; i<=n;i++) scanf ("%LF", &input[i]), sum+=Input[i]; +          for(intI=1; i<=n;i++) num[i]=input[i]/sum*20000; - DP (); -  the         intK; -          for(intI=10000; i>=0; i--)if(Dp[i]) {k=i; Break;}Wuyi          the          while(k>0){ - S.push (Road[k]); Wuk-=Num[road[k]]; -         } About         BOOLfirst=1; $          while(!S.empty ()) { -             if(first) printf ("%d", S.top ()), first=0; -             Elseprintf"%d", S.top ()); - S.pop (); A         } +printf"\ n"); the     } -     return 0; $}

POJ 1853 knapsack problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.