Greedy Gift Givers

A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to any or all of the other friends. Likewise, each friend might or might not receive money from any or all of the other friends. Your goal in this problem is to deduce how much more money each person gives than they receive.

The rules for gift-giving are potentially different than you might expect. Each person sets aside a certain amount of money to give and divides this money evenly among all those to whom he or she is giving a gift. No fractional money is available, so dividing 3 among 2 friends would be 1 each for the friends with 1 left over -- that 1 left over stays in the giver's "account".

In any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.

Given a group of friends, no one of whom has a name longer than 14 characters, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts, determine how much more (or less) each person in the group gives than they receive.

IMPORTANT NOTE

The grader machine is a Linux machine that uses standard Unix conventions: end of line is a single character often known as '\n'. This differs from Windows, which ends lines with two charcters, '\n' and '\r'. Do not let your program get trapped by this!

PROGRAM NAME: gift1

INPUT FORMAT

Line 1: The single integer, NP
Lines 2..NP+1: Each line contains the name of a group member
Lines NP+2..end: NP groups of lines organized like this:

The first line in the group tells the person's name who will be giving gifts.The second line in the group contains two numbers: The initial amount of money (in the range 0..2000) to be divided up into gifts by the giver and then the number of people to whom the giver will give gifts, NGi (0 ≤ NGi≤ NP-1).If NGi is nonzero, each of the next NGi lines lists the the name of a recipient of a gift.

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

OUTPUT FORMAT

The output is NP lines, each with the name of a person followed by a single blank followed by the net gain or loss (final_money_value - initial_money_value) for that person. The names should be printed in the same order they appear on line 2 of the input.

All gifts are integers. Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible that meets this constraint. Any money not given is kept by the giver.

SAMPLE OUTPUT (file gift1.out)

dave 302
laura 66
owen -359
vick 141
amr -150

好吧。。。这是一道很简单的模拟题,不过因为在usaco上没经验,提交的格式正确啊,导致交了几次才过。。还是没想通为什么。好像以文件的形式输入输出,是不是c与c++就不能混编了啊。。还是有其他的方法呢?这个要考虑一下。。。还有就是,题目里强调的end of line is a single character often known as '\n'. This differs from Windows, which ends lines with two charcters, '\n' and '\r'. Do not let your program get trapped by this!到底是嘛意思啊,是不是说每次读取都是从头再开始?好纠结~

题目中用到了STL中的map;虽然用STL会很慢。。不过我map用的不多,权当锻炼一下吧:下面总结一下map的用法:

定义:map <int,string> a;        //其中int型为key,map提供的是基于key的快速检索功能;也就是说,map能够提供一对一的检索,为int型找到其对应的string型

不过这道题目应该反过来:)

赋值:此处说一下最简单的数组赋值: a[int]=string      //为int型提供一对一的关系,能够快速的从int型找到string型;

这道题中,应该是这样的:  a[string]=i

代码:
View Code

 1 /*
 2 ID: jings_h1
 3 PROG: gift1
 4 LANG: C++
 5 */
 6
 7 #include<iostream>
 8 #include<fstream>
 9 #include<string.h>
10 #include<map>
11 int res[100];
12 char name[100][20];
13 using namespace std;
14 int main(){
15     ofstream fout ("gift1.out");
16     ifstream fin ("gift1.in");
17     int n;
18     fin>>n;
19        memset(res,0,sizeof(res));
20        map <string,int> a;
21        for(int i=1;i<=n;i++){
22                string temp1;
23                fin>>name[i];
24                temp1=name[i];
25                a[temp1]=i;
26                }
27        for(int j=1;j<=n;j++){
28                string temp;
29                fin>>temp;
30                int sum,num;
31                fin>>sum>>num;
32                int k=0;
33                for(k=sum;k>0;k--){
34                        if(k%num==0)
35                            break;
36                            }
37                int point=a[temp];
38                res[point]+=(0-k);
39                for(int g=1;g<=num;g++){
40                        string temp2;
41                        fin>>temp2;
42                        int point2=a[temp2];
43                        res[point2]+=k/num;
44                        }
45                        }
46        for(int i=1;i<=n;i++){
47                fout<<name[i]<<" "<<res[i]<<endl;;
48           //     if(i<n)
49             //       fout<<endl;
50                }
51      //  fout<<"\n\r";
52        return 0;
53        }
54     

usaco 1.1 greedy gift givers相关推荐

  1. USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers

    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...

  2. USACO题解——Section 1.2——Greedy Gift Givers

    题目地址:https://train.usaco.org/usacoprob2?a=BGOMbIJsisd&S=gift1. 或者我的OJ网站,http://47.110.135.197/pr ...

  3. 贪婪的送礼者Greedy Gift Givers [USACO 1.2]

    贪婪的送礼者Greedy Gift Givers [USACO 1.2]题目描述: 有一群(N个)要互送礼物的朋友,现在要确定每个人送出的钱比收到的钱多多少.每个人都准备了一些钱来送礼物,而这些钱将会 ...

  4. Greedy Gift Givers

    原题地址 Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange g ...

  5. USACO Section 1.2 Greedy Gift Givers (简单查找)

    2018-3-25 changed 题目大意就是说我们要互相 " 送钱 " ,一共NP个人,指定某一个人将sum这么多的钱分给num个人,那么这些人每个人多了sum/num,送钱的 ...

  6. [USACO1.1]贪婪的送礼者Greedy Gift Givers

    题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人.然而,在任何一群朋友中 ...

  7. USACO1.1.2 - Greedy Gift Givers

    贪婪礼品送货员 一组NP(2≤NP≤10)唯一命名的朋友决定交换礼物的钱.这些朋友中的每一个可能或可能不会给任何或所有其他朋友一些钱.同样,每个朋友可能或可能不从任何或所有其他朋友接收钱.你在这个问题 ...

  8. YTU ---1402-Greedy Gift Givers 贪婪的送礼者

    1402: 1.1.2 Greedy Gift Givers 贪婪的送礼者 Time Limit: 1 Sec   Memory Limit: 64 MB Submit: 31   Solved: 1 ...

  9. USACO 1.0_Greedy Gift Givers

    2019独角兽企业重金招聘Python工程师标准>>> /* ID: zfb2 LANG: C++ TASK: gift1 */ #include <iostream> ...

  10. USACO 2017 December Contest Platinum T3: Greedy Gift Takers

    题目大意 有 N(1≤N≤1e5)头牛按顺序排成一列,编号从 1 到 N,1 号牛在队头,N 号牛在队尾. 每次位于队头的牛 i 拿到一个礼物,然后插入到从队尾数ci​头牛之前的位置..举个栗子: 初 ...

最新文章

  1. Java项目:在线拍卖竞价系统(java+SpringBoot+FreeMarker+Mysql+redis)
  2. ios 折线图_《解神者》ios和安卓互通吗 ios和安卓互通分析
  3. 先给自己定个小目标,比如写个爬虫程序
  4. rust实战入门到进阶(1)
  5. 这是私人的事,法官大人
  6. [转]CNN目标检测(一):Faster RCNN详解
  7. js html 转换为富文本,如何将富文本得到的html转换为pdf?
  8. linux7 vnc看不到桌面,VNC Viewer轻松连接远程CentOS7桌面
  9. 双鸭山2021年高考成绩查询,黑龙江双鸭山2021年上半年教师资格证成绩查询时间...
  10. 背景色渐变html代码,求html文字背景色渐变的代码
  11. [R语言]读取文件夹下所有子文件夹中的excel文件,并根据分类合并。
  12. 主子式大于等于零的矩阵是半正定矩阵的证明方法之一
  13. macOS 如何设置壁纸
  14. 米兔机器人自主编程_可编程米兔机器人 让成年人回归童心的玩具
  15. 很好的万年历代码。随时可运行
  16. 机器学习项目实战合集列表
  17. ShapeShift、DAOs和工作的未来
  18. SSMS安装失败及解决
  19. transforms.Compose和transforms.ToTensor()
  20. 工控系统的全球安全现状:全球漏洞实例分析

热门文章

  1. java实现pdf旋转_java生成pdf旋转_如何使用Java旋转PDF文档中的图像?
  2. win7怎么关闭配置计算机,Win7电脑怎么设置定时关机?
  3. 【解决】UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xef in position 0: ordinal not in range(128
  4. CF379C-New Year Ratings Change
  5. 计算机专业女生节祝福语,大学女生节简短祝福语
  6. 憎恨之心最强套装攻略_憎恨之心装备选择 | 手游网游页游攻略大全
  7. mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
  8. 包装严重的 IT 圈,作为面试官,是如何甄别应聘者呢?
  9. 稳压二极管的原理及应用
  10. win7怎么重置计算机,win7系统怎么重置网络?win7重置网络到初始状态的方法