六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 25|回复: 0

【水题】USACO Greedy Gift Givers

[复制链接]

升级  68.4%

272

主题

272

主题

272

主题

进士

Rank: 4

积分
842
 楼主| 发表于 2013-1-26 13:33:36 | 显示全部楼层 |阅读模式
进入USACO要注册才可看题: http://train.usaco.org/usacogate

题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/11%5C106.asp

SAMPLE INPUT (file gift1.in)
5
dave
laura
owen
vick
amr
dave
200 3
laura
owen
vick
owen
500 1
dave
amr
150 2
vick
owen
laura
0 2
amr
vick
vick
0 0

SAMPLE OUTPUT (file gift1.out)
dave 302
laura 66
owen -359
vick 141
amr -150


多重for循环嵌套了相同变量……纠结了好久  无奈///Orz...
……暴力解题……水题不多说……

/*ID: 1006100071PROG: fridayLANG: C++*/#include <iostream>#include <fstream>#include <algorithm>#include <string>#include <set>//#include <map>#include <queue>#include <utility>#include <iomanip>#include <stack>#include <list>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <ctype.h>using namespace std;struct person{char name[20];int give, receive;}x[15];int main(){/*freopen ("friday.in", "r", stdin);freopen ("friday.out", "w", stdout);*/int n, i, j, mon, t, k;char name[20];scanf ("%d", &n);for (i = 0; i < n; i++)scanf ("%s", x.name);for (i = 0; i < n; i++){scanf ("%s", name);scanf ("%d%d", &mon, &t);if (!mon){for (j = 0; j < t; j++)scanf ("%s", name);continue;}if (!t){x[j].receive += mon;continue;}for (j = 0; j < n; j++)if (!strcmp (name, x[j].name))break;x[j].give += mon;x[j].receive += mon % t;for (j = 0; j < t; j++){scanf ("%s", name);for (k = 0; k < n; k++)if (!strcmp (name, x[k].name))break;//cout << "----------" <<  mon / t << endl;x[k].receive += mon / t;}}for (i = 0; i < n; i++)printf ("%s %d\n", x.name, x.receive - x.give);return 0;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表