USACO Section 1.1: Greedy Gift Givers

 1 /*

 2 ID: leetcod3

 3 PROG: gift1

 4 LANG: C++

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 #include <cstdio>

19 #include <cstdlib>

20 #include <limits>

21 #include <stack>

22 

23 using namespace std;

24 

25 ofstream fout ("gift1.out");

26 ifstream fin ("gift1.in");

27 

28 int main() {

29     int N;

30     fin >> N;

31     map<string, int> S;

32     vector<string> ans;

33     for (int i = 0; i < N; i++) {

34         string s;

35         fin >> s;

36         S[s] = 0;

37         ans.push_back(s);

38     }

39     for (int i = 0; i < N; i++) {

40         string from;

41         fin >> from;

42         int num, c;

43         fin >> num >> c;

44         for (int j = 0; j < c; j++) {

45             string to;

46             fin >> to;

47             S[to] += num / c;

48             S[from] -= num / c;

49         }

50     }

51     for (int i = 0; i < ans.size(); i++) {

52         fout << ans[i] << " " << S[ans[i]] << endl;

53     }

54     return 0;

55 }

 

你可能感兴趣的:(USACO)