P1201 USACO1.1 贪婪的送礼者

模拟题 是一道练STL的好题

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef unsigned long long ull;
 5 
 6 namespace io {
 7     const int SIZE = 1e7 + 10;
 8     char inbuff[SIZE];
 9     char *l, *r;
10     inline void init() {
11         l = inbuff;
12         r = inbuff + fread(inbuff, 1, SIZE, stdin);
13     }
14     inline char gc() {
15         if (l == r) init();
16         return (l != r) ? *(l++) : EOF;
17     }
18     void read(int &x) {
19         x = 0; char ch = gc();
20         while(!isdigit(ch)) ch = gc();
21         while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
22     }
23 } using io::read;
24 
25 int main(){
26     int np;
27     cin>>np;
28     string s[13];
29     map <string, int> get;
30     map <string, int> out;
31     string name;
32     string name0;
33     int n, m;
34     for (int i = 1; i <= np; i++) cin>>s[i];
35     for (int i = 1; i <= np; i++){
36         cin>>name;
37         cin>>n>>m;
38         if (m){
39             out[name] += (n / m) * m;
40             for (int j = 1; j <= m; j++){
41                 cin>>name0;
42                 get[name0] += n / m;
43             }
44         }
45     }
46     for (int i = 1; i <= np; i++)
47         cout<<s[i]<<' '<<get[s[i]] - out[s[i]]<<endl;
48     return 0;
49 }

 

posted @ 2019-05-23 23:35  Misuchii  阅读(138)  评论(0编辑  收藏  举报