USACO Section 1.1 Greedy Gift Givers
2013-11-22 21:06
309 查看
/* ID: lucien23 PROG: gift1 LANG: C++ */ #include<iostream> #include<fstream> #include<string> #include<map> using namespace std; int main() { ifstream infile("gift1.in"); ofstream outfile("gift1.out"); if(!infile || !outfile) { cout<<"file operation failure!"<<endl; return -1; } int NP; infile>>NP; map<string,int> mapFriends; string *friends=new string[NP]; string name; for (int i=0;i<NP;i++) { infile>>name; friends[i]=name; mapFriends[name]=0; } string giver; string receiver; int NG,totalMoney,evenMoney; for (int i=0;i<NP;i++) { infile>>giver>>totalMoney>>NG; if(NG==0) continue; evenMoney=(totalMoney-totalMoney%NG)/NG; mapFriends[giver]-=evenMoney*NG; for (int j=0;j<NG;j++) { infile>>receiver; mapFriends[receiver]+=evenMoney; } } for (int i=0;i<NP;i++) { outfile<<friends[i]<<" "<<mapFriends[friends[i]]<<endl; } delete[] friends; return 0; }
相关文章推荐
- USACO-Section1.1 Greedy Gift Givers【查找】
- 【USACO】【Section1.1】Greedy Gift Givers
- 【USACO】【Section1.1】Greedy Gift Givers
- USACO Section1.1 Greedy Gift Givers
- USACO-Section1.1 Greedy Gift Givers
- USACO:Section 1.1 Greedy Gift Givers
- USACO Section 1.1 Greedy Gift Givers
- USACO-Section1.1 Greedy Gift Givers
- USACO - Chapter1 Section 1.1 - Greedy Gift Givers
- USACO Section1.1 Greedy Gift Givers
- USACO Section 1.1 Greedy Gift Givers
- USACO-Section1.1 Greedy Gift Givers [hash表]
- USACO 1.1 Greedy Gift Givers (gift1)
- P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
- 洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
- USACO Section 1.1 : Greedy Gift Givers
- USACO1.1 Greedy Gift Givers 比较分析
- [USACO1.1]贪婪的送礼者Greedy Gift Givers
- [USACO] Section1.1 Greedy Gift Givers[线性时间查找]
- USACO-Section1.1 Greedy Gift Givers[...]