USACO Section1.1 Greedy Gift Givers

USACO-Section1.1 Greedy Gift Givers 2017-05-25题目大意:对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。 然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。 给出一群朋友,没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表 阅读详情

第一次用这个网站的看USACO分类的“关于USACO“,,肯定有用,不然你会死在某些你想吐血的地方

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 starting 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

OUTPUT EXPLANATION
Five names: dave, laura, owen, vick, amr Let’s keep a table of the gives (money) each person ‘has’:
dave laura owen vick amr
0 0 0 0 0
First, ‘dave’ splits 200 among ‘laura’, ‘owen’, and ‘vick’. That comes to 66 each, with 2 left over
-200+2 66 66 66 0
Second, ‘owen’ gives 500 to ‘dave’:
-198+500 66 66-500 66 0
Third, ‘amr’ splits 150 between ‘vick’ and ‘owen’:
302 66 -434+75 66+75 -150
Fourth, ‘laura’ splits 0 between ‘amr’ and ‘vick’; no changes:
302 66 -359 141 -150
Finally, ‘vick’ gives 0 to no one:
dave laura owen vick amr
302 66 -359 141 -150

中文题目
Greedy Gift Givers
贪婪的礼物送礼者
译 by tim green
对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for those who view gift giving with cynicism)。
在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。
然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。
给出一群朋友, 没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表,
请确定每个人收到的比送出的钱多的数目。
IMPORTANT NOTE
测试系统是 Linux 符合标准的 Unix 的协定。
用’\n’作为行的结束。
这和 Windows 系统用’\n’ 和 ‘\r’作为行的结束是不同的。
你的程序不要被这困住了。
PROGRAM NAME: gift1
INPUT FORMAT
第 1 行: 人数NP,2<= NP<=10
第 2到 NP+1 行: 这NP个在组里人的名字 一个名字一行
第NP+2到最后: 这里的NP段内容是这样组织的:
第一行是将会送出礼物人的名字。
第二行包含二个数字: 第一个是原有的钱的数目(在0到2000的范围里),第二个NGi是将收到这个送礼者礼物的人的个数 如果 NGi 是非零的, 在下面 NGi 行列出礼物的接受者的名字,一个名字一行。

【解题思路】用map来记录名字,,,我以为输出可以用迭代器从begin()到end(),,,然而还不料,万恶的平衡树,。。。只能存了

/*
ID:***
LANG:C++
TASK:gift1 
*/
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
map<string,int>mp;
map<string,int>::iterator it;
int tot;
string ss[12];
inline void read(int i){
    string s;
    cin>>s;
    ss[i]=s;
    mp[s]=++tot;
}
inline int readin(){
    string s;
    cin>>s;
    return mp[s];
}
int n,m;
int w[15];
int main(){
    freopen("gift1.in","r",stdin);
    freopen("gift1.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1; i<= n; i++)
        read(i);
    for(int i = 1; i<= n; i++){
        int u=readin(),ww;
        scanf("%d%d",&ww,&m);
        if(m==0){w[u]+=ww;continue;}
        int q=ww/m;
        w[u]+=-q*m;
        for(int j = 1; j<=m; j++){
            int v=readin();
            w[v]+=q;
        }
    }
    for(int i = 1; i <= n; i++)
        cout<<ss[i]<<" "<<w[mp[ss[i]]]<<endl;
    return 0;
}

要数据的评论!!!

微信小程序码 createWxaCodeUnlimit 生成总是报错 41030 的解决方案 41030错误本质上就是路径不合法。路径多写了一个斜杠路径带了参数小程序版本未发布或 app.json 配置不一致。如果确认页面存在,可以通过来跳过检查。微信小程序 getUnlimitedQRCode 官方文档路径前不能加 /,参数放 scene,发布版本要有这个页面,不行就关掉 check_path。 阅读详情

相关推荐

MATLAB闪退别慌!5分钟搞定Windows系统预设文件修复(附详细截图)

本文针对MATLAB在Windows系统下频繁闪退的问题,提供了快速有效的解决方案。核心在于修复或重置损坏的MATLAB预设文件,通过图文并茂的五步法,指导用户定位AppData目录、重命名预设文件夹,从而让MATLAB自动生成全新配置以解决闪退。文章还涵盖了问题诊断、设置备份及进阶排查方法,帮助用户彻底根除启动故障。

weixin_29234423的博客 925

USACO1.1 Greedy Gift Givers(gift1)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34283445的博客 130

Pico-实时预览工具PreviewTool

Unity XR SDK与Preview Tool下载链接:SDK - Pico Developer Platform1、下载Preview Tool后,将PreviewTool的APK先安装在VR头显里2、在PC端打开Preview Tool.exe文件Window -> Package Manager -> Add package from disk,选择下载的pico sdk中的package.json(如下图),Open导入。Edit -> Project Settings,设置设备和安卓版本,如下

晴天下的大头娃娃 4251

Greedy Gift Givers

原题地址 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 o

babyron的专栏 2616

Label Studio保姆级教程:从零搭建医疗影像标注平台(DICOM格式支持)

本文提供基于Label Studio从零搭建医疗影像标注平台的保姆级教程。针对DICOM格式支持,详细阐述了环境部署、DICOM深度集成与预处理、团队协作权限管理以及质量审核闭环等核心环节,旨在构建一个高效、可落地的医疗AI数据标注解决方案,助力模型落地。

nft7creator的博客 303

Vivado与VCS+Verdi联合仿真环境搭建全攻略

本文详细介绍了如何搭建Vivado与VCS+Verdi联合仿真环境,旨在解决Vivado Simulator在大型FPGA验证中速度慢、调试弱的问题。通过指导工具版本配对、环境变量设置、关键参数配置及Xilinx仿真库编译,帮助工程师高效整合Vivado的设计管理、VCS的高速仿真与Verdi的深度调试能力,从而显著提升验证效率。

weixin_29219189的博客 576

【USACO1.1_2】★Greedy Gift Givers 贪婪的礼物送礼者

对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for those who view gift giving with cynicism). 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物 的人. 然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较 多的钱.

zwcwu31的专栏 1950

普罗米修斯监控达梦数据库集群

-----------------------------------新增文件---------------------------------------注:图上即为启动成功,如果没有问题,则使用nohup后台启动程序。官网地址:https://github.com/gy297879328/dameng_exporter。注:prometheus的对数据库的指标采集如果高于60s一次,请手动修改提供表盘中的计算值。修改dameng_exporter.config配置文件,修改账号密码的部分。

weixin_49985403的博客 1680

USACO 1.1 Greedy Gift Givers (gift1)

/* ID: haolink1 PROG: gift1 LANG: C++ */ //#include #include #include #include #include using namespace std; //compute the member position for earnings array unsigned short MemberPosition(char**

Hello World! 1013

轨迹优化 | 基于ESDF的共轭梯度优化算法(附ROS C++/Python仿真)

共轭梯度法的核心原理是求解优化问题的共轭向量组作为优化方向,由于优化方向间彼此正交,故每次迭代只需沿着一个方向寻优而互不影响。本文设计基于ESDF的障碍约束、曲率约束和平滑约束,基于ROS C++和Python提供了共轭梯度法的轨迹优化实践案例

FRIGIDWINTER的博客 1万+

28、时间敏感网络中可靠性感知的综合路由与调度

本文针对时间敏感网络(TSN)中现有路由与调度机制主要关注时间触发(TT)流量而忽略其他类型流量效用的问题,提出了一种可靠性感知的综合路由与调度机制。通过将具有不同可靠性和延迟要求的各类流量的联合路由与调度问题形式化为基于优化模理论(OMT)的混合整数规划问题,设计了完整的路由约束与调度约束,并分析了不同类型流量的传输效用,设定了优化目标以提升整体网络性能。实验结果表明,该机制在满足TT流量严格时延与可靠性要求的同时,显著提高了AVB和BE等非关键流量的传输效用,实现了多类型流量的高效协同传输。

hhh00的博客 95

USACO Section 1.1 Greedy Gift Givers

没有分数的钱可用,所以在2个朋友中,除了3个,对于剩下1个的朋友,每个1个,剩下1个留在提交者的“帐户”中。给予一群朋友,其中没有一个姓名长度超过14个字符,团体中的每个人花费的礼物和每个人给予礼物的(子)列表的朋友,确定多少(或较少)组中每个人给予的比他们收到。这不同于Windows,它结束了两个字符'\ n'和'\ r'的行。第一,'dave'把自己的200元平均分给'laura','owen'和'vick'三人。第四,'laura'把自己的0元平均给了'amr' and 'vick';

YanLucyqi的博客 577

19、多项式基算术:原理与运算详解

本文深入探讨了有限域 $GF(2^m)$ 中的多项式基算术,详细介绍了加法、减法、乘法和平方运算的原理与实现方法。重点分析了多项式基表示形式、模约简技术以及乘法优化策略,如高基数乘法、并行与顺序乘法器设计,并提到了Karatsuba-Ofman算法在减少乘法次数方面的优势。此外,文章还讨论了多项式基算术在密码学、编码理论等领域的应用前景,并展望了未来在高效算法设计与硬件加速方面的研究方向。

yellow的专栏 150

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

P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。给出一群朋友,没有人的名字会长于 14 字...

日拱一卒,功不唐捐 2836

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

USACO Section1.2 Greedy Gift Givers 翻译&解题报告

Task 'gift1': Greedy Gift GiversA 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 some or all of th...

竹喧的博客 729

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

题目地址:https://train.usaco.org/usacoprob2?a=BGOMbIJsisd&S=gift1。 或者我的OJ网站,http://47.110.135.197/problem.php?id=5184。 题目 A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange ...

努力中的老周的专栏 7657

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

【USACO】【Section1.1】Greedy Gift Givers

小白题,也没啥好说的。关键我的算法感觉特别菜的一点是每次要遍历数组从人名找对应的编号,这个效率就很低了。看了ANALYZE里面也是这样的。不过它比我好的一点是我多余设置了initial_money变量,确实是不需要的。还有一点就是有可能接受礼物的人是0个,要判断。如果是0就不用60~67行了,而且60行的分母也会为0; 1 /*ID:Moment1991 2 PROG:gif...

weixin_30604651的博客 126

USACO Training Section 1.2 Greedy Gift Givers

这道题难度不大,算是纯纯的模拟题目,但是交了5次都没有过,原因是没有把送礼者剩余的钱加回来,加回来就AC了。 因为数据很小(2 <= NP <= 10)所以不用优化。 保存人的名字的时候其实可以用vector<string>,理论上应该更加方便、高效。 代码如下: /* ID: aircraf1 PROB: gift1 L...

weixin_30311605的博客 124

USACO之Section 1.1.2 PROB Greedy Gift Givers

这道题如果按照一般的思路来写的话,要有反复的去确定发钱的人名对应的是第几个人。所以决定采用map键值对应的方法去写。 map键值对应: 这里先写用到的有点,以后还会有所补充。参考: http://blog.csdn.net/flqbestboy/article/details/8184484 注意: map<string,int>以及键值对的赋值,和用迭代器读取键值对(或直接读取操作)。

qq_36079132的博客 287

USACO Section 1.1-2 Greedy Gift Givers

Greedy Gift Givers 贪婪的送礼者     对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。     在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。     然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。     给出一群朋友,没有人...

diaoluo1817的博客 166
上一篇: 关于USACO
下一篇: USACO Section4.2 The Perfect Stall &&POJ1274
Freddddddddddd
博客等级 码龄10年 2粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值