usaco Greedy gift givers solution: http://ideone.com/49AVHb
/* ID: [your usacogate ID here] PROG: gift1 LANG: C++ */ #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { freopen("gift1.in", "r", stdin); freopen("gift1.out", "w", stdout); int n, a, b, k=0, acc[15]={0}, idx, tmp; vector <string> v; string s; scanf("%d", &n); for(int i=0; i<n; i++) cin>>s, v.push_back(s); for(int i=0; i<n; i++) { cin>>s; scanf("%d%d", &a, &b); idx=find(v.begin(), v.end(), s)-v.begin(); tmp=idx; for(int j=0; j<b; j++) { cin>>s; idx=find(v.begin(), v.end(), s)-v.begin(); acc[idx]+=a/b, acc[tmp]-=a/b; } } for(vector <string>::iterator i=v.begin(); i!=v.end(); i++) { cout<<(*i)<<" "<<acc[k]<<endl; k++; } return 0; }
note: function find() belongs to <algorithm> C++ library, and it helps you to find position/index of sepcific thing in C++ vectors. for ref: http://stackoverflow.com/a/15099748/2948746
No comments:
Post a Comment