UVA 119 Greedy Gift Givers

    xiaoxiao2025-06-03  81

    题目:注意这一段 Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible. 一个准备买礼物的钱是他预留的,不是全部用光的,但是他要尽可能的多用,且给每个他所给礼物的人是平均的。比如:dave 200 3 laura owen vick ——dave有200他最后花掉的是(200/3)*3=66*3(整除) laura owen vick各得到66。

    分析:模拟 我用了一下vector动态数组 当然普通数组也行

    注意:

    #include "string" #include "iostream" #include "vector" #include"algorithm" #include"cstring" using namespace std; int main() { int n;int cost_and_get[10],flag=0; while(cin>>n) { if(flag!=0) cout<<endl; flag++; memset(cost_and_get,0,sizeof(cost_and_get)); vector<string> name; for(int i=0;i<n;i++) { string s; cin>>s; name.push_back(s); } for(int i=0;i<n;i++) { string temp_name;int out,money,m,in; cin>>temp_name; vector<string>::iterator p=find(name.begin(),name.end(),temp_name); out=p-name.begin(); cin>>money>>m; for(int j=0;j<m;j++) { cin>>temp_name; vector<string>::iterator p=find(name.begin(),name.end(),temp_name); in=p-name.begin(); cost_and_get[out]-=money/m; cost_and_get[in]+=money/m; } } for(int i=0;i<n;i++) { cout<<name[i]<< ' '<<cost_and_get[i]<<endl;; } } return 0; }
    最新回复(0)