Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 22nd, 2010, 02:18 AM
 MarkDej
Registered User

Join Date: Nov 2010
Posts: 3
Time spent in forums: 32 m 10 sec
Reputation Power: 0

Hi everybody

I am a beginner in the subject of algorithms, and i seek some help in finding the proper algorithm to solve the following problem:

Two brothers received together some gifts. They know the value of each gift, which is a positive integer.

They want to divide the gifts according to their values, so that the total value of the gifts that each of them receives are equal.

They realized that this can not necessarily be done for all the gifts, therefore, they accept to share some of the gifts that will remain , but these shared gifts should have the least possible values.

Write a program that gives a fair sharing!

Input specification:
In the input.txt file, the first row contains the number of gifts n which can be 1 <= n <= 80.
The second row contains n positive integers separated by spaces, these integers are the values of each gift.

Output specification:
In the output.txt file, the first row should contain the total value (sum) of the remaining gifts (shared gifts).

The second row should contain integers separated by spaces and these integers represent the position order of the gifts that one brother received.

The third row should contain integers separated by spaces and these integers represent the position order of the gifts that the other brother received.

Program can be written with any of the following languages:
C, C++, JAVA or PASCAL
Time limit: 0.5 seconds
Memory limit: 64MB

Example :

input.txt
6
10 3 12 5 15 6

output.txt
15
6 3
4 2 1

#2
November 22nd, 2010, 03:11 AM
 requinix
Forgetful

Join Date: Mar 2007
Location: Washington, USA
Posts: 13,478
Time spent in forums: 5 Months 2 Weeks 2 Days 5 h 4 m 58 sec
Reputation Power: 9259
Code:
```input.txt
6
10 3 12 5 15 6

output.txt
15
6 3
4 2 1```

Uh, what? Where'd the 5, 10, and 12 go? Where'd the 1, 2, and 4 come from?

#3
November 22nd, 2010, 03:29 AM
 MarkDej
Registered User

Join Date: Nov 2010
Posts: 3
Time spent in forums: 32 m 10 sec
Reputation Power: 0
Quote:
 Originally Posted by requinix Code: ```input.txt 6 10 3 12 5 15 6 output.txt 15 6 3 4 2 1``` Uh, what? Where'd the 5, 10, and 12 go? Where'd the 1, 2, and 4 come from?

the input.txt has 2 lines
first one has the total number of the gifts; in this case 6 gifts.

in the output.txt
the first row contains the sum of the remaining gift's values, which should have the least possible value that will not be given to any of the persons: in this case the only remaining gift is gift5 which has a value=15

the second row contains the gifts taken by one of the persons:

the third row contains the gifts taken by the other:

so each person took total value of 18.
and they share gift5 which has a value of 15.

Sorry for the poor explanation.

 Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Algorithm for 2 person fair division - Please Help -

## Developer Shed Advertisers and Affiliates

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |