USACO Section 1.1 Greedy Gift Givers

大意略。

/*
ID:g0feng1
LANG:C++
TASK:gift1
*/

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

ofstream fout("gift1.out");
ifstream fin("gift1.in");

map<string, int > Map, Count;
map<int, string> sa;
map<string, int>::iterator it1;


void init()
{
	sa.clear();
	Map.clear();
	Count.clear();
}

int n;

void read_case()
{
	init();
	int val, people;
	string str, sen, rec;
	fin>>n;
	for(int i = 0; i < n; i++)
	{
		fin>>str;
		Map[str] = 0;
		sa[i] = str;
	}
	for(int i = 0; i < n; i++)
	{
		fin>>sen;
		fin>>val>>people;
		Count[sen] = val;
		Map[sen] += val;
		if(people == 0) continue;
		Map[sen] -= val;
		if(val % people != 0) Map[sen] += val % people;
		for(int i = 0; i < people; i++)
		{
			fin>>rec;
			Map[rec] += val / people;
		}
	}
}

void solve()
{
	read_case();
	for(int i = 0; i < n; i++)
	{
		int a = Map[sa[i]], b = Count[sa[i]];
		fout<<sa[i]<<" "<<a-b<<endl;
	}
}

int main()
{
	solve();
	return 0;
}


你可能感兴趣的:(USACO Section 1.1 Greedy Gift Givers)