1.题意:一群人之间每人准备了一些钱互相送(你们好无聊(⊙o⊙)…),数据给出了每人准备的金额与送出的对象,且保证送给每人的金额是平均的,最后要求出每个人收到的比送出的钱多的数目。
2.分析:模拟题,注意两点细节:首先不是求每人最后剩多少钱,只要把收到的钱减去送出的钱就是结果了;还有如果准备的钱不能被送出的人数整除,那就尽可能多给;关键就是怎么统计和查找收钱人,这里建立map<string,int> M将人名对应到数字上方便查询和统计
3.代码:
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <map> 5 using namespace std; 6 int PeopleNum; 7 struct Node 8 { 9 string s; 10 int give,get; 11 }L[15]; 12 map<string,int> M; 13 void Init() 14 { 15 for(int i=0;i<PeopleNum;i++) 16 { 17 cin>>L[i].s; 18 M[L[i].s]=i; 19 } 20 for(int i=0;i<PeopleNum;i++) 21 { 22 int a,b; 23 string t1,t2; 24 cin>>t1>>a>>b; 25 if(b==0) continue; 26 L[M[t1]].give+=a/b*b; 27 a/=b; 28 for(int i=0;i<b;i++) 29 { 30 cin>>t2; 31 L[M[t2]].get+=a; 32 } 33 } 34 } 35 void Solve() 36 { 37 for(int i=0;i<PeopleNum;i++) 38 cout<<L[i].s<<" "<<L[i].get-L[i].give<<endl; 39 } 40 int main() 41 { 42 while(scanf("%d",&PeopleNum)!=EOF) 43 { 44 Init(); 45 Solve(); 46 } 47 return 0; 48 }