P1201 [USACO1.1] Greedy Gift Givers, p1201usaco1.1

Source: Internet
Author: User

P1201 [USACO1.1] Greedy Gift Givers, p1201usaco1.1
Description

For a Group of Friends (NP members) who want to send gifts to each other, GY needs to determine the amount of money each person sends more than what he receives. In this case, everyone has prepared some money to give gifts, and the money will be evenly distributed to those who will receive his gift. However, among any group of friends, some will give more gifts (probably because there are more friends) and some may have prepared more money. Given a group of friends, no one's name will be longer than 14 characters, giving a list of people who will spend money on gifts and will receive their gifts, determine the amount of money each person receives.

Input/Output Format Input Format:

Row 1st: Number of workers NP, 2 <= NP <= 10

Line 3 to line NP + 1: The NP name in the group is a name row.

NP + 2 to the end:

The content of Section I is organized as follows:

The first line is the name of the present person.

The second row contains two numbers: the first is the original amount of money (in the range of 0 to 2000 ), the second NGi is the number of people who will receive the gift from this person. If NGi is non-zero, the NGi line below lists the name of the recipient of the gift, one name row.

Output Format:
Input and Output sample Input example #1:
5davelauraowenvickamrdave200 3lauraowenvickowen500 1daveamr150 2vickowenlaura0 2amrvickvick0 0
Output sample #1:
dave 302laura 66owen -359vick 141amr -150
Description

The question translation is from NOCOW.

USACO Training Section 1.1

STL great!

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<map> 6 using namespace std; 7 int n,num,mon; 8 map<string,int>mp; 9 string a;10 string name[101];11 int main()12 {13     scanf("%d",&n);14     for(int i=1;i<=n;i++)15     {16         cin>>a;17         mp[a]=0;18         name[i]=a;19     }20     for(int i=1;i<=n;i++)21     {22         cin>>a;23         scanf("%d%d",&mon,&num);24         int will=0;25         if(num!=0)26         {27             will=mon/num;28             mp[a]=(mon-floor(will*num))-mon+mp[a];    29         }30         for(int i=1;i<=num;i++)31         {32             cin>>a;33             mp[a]+=will;34             //cout<<a<<"****"<<mp[a]<<endl;35             //cout<<mp["laura"]<<"***"<<endl;36         }37     }38     for(int i=1;i<=n;i++)39     {40         cout<<name[i]<<" "<<mp[name[i]]<<endl;41     }42     return 0;43 }

 

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.