男女舞伴贪心

本文介绍了一个关于舞蹈晚会中男女舞伴配对的问题。通过分析不同颜色的鞋子和鞋带数量,采用贪心算法确定最大可能的配对数量。文章包含输入输出样例及解析。

H.Dance Floor
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 177 (39 users)Total Accepted: 19 (17 users)Special Judge: No
Description

Manao owns a dance floor which hosts dances every Saturday night. A feature of his dance floor is that they also rent dance shoes. There are shoes of n different colors for rent. We will enumerate the colors from 1 to n. For each i, there are Mi pairs of men's shoes, Wi pairs of

women's shoes and Si pairs of shoelaces of color i.

Of course, each dancer wants to have the shoes and shoelaces of the same color. Determine the maximum number of pairs that can dance if each pair consists of a man and a woman. Note

that the two dancers in the pair do not have to wear the shoes of the same color.

Input

The first line contains an integer n(1  n  100000). The i-th of the following n lines contains three space-separated integers Mi, Wi, Si (0  Mi, Wi, Si  20000).

Output

Print a single number in a single line — the maximum number of pairs of dancers that can dance in rented shoes.

Sample Input

1

5 7 5

Sample Output

2

题意:给出n种颜色的鞋带

下面有n行

每行三个数m,w,s分别是男生鞋,女生鞋,i种鞋带的数目

每个人的鞋子必须与鞋带颜色相同,但男生和女生的鞋的颜色不一定要相同

求最多能得到多少对

分析:

哎。。这题比赛的时候没有做出来,回去从晚上十二点想到了凌晨三点半,差不多想明白了,真佩服我自己。。QAQ。。。。其实只需要四行代码

  while(cin>>n)
        {
            int A,B,C;
            A = B =C = 0;
            while(n--)
            {
                int a,b,c;
                A += min(a,c);
                B += min(b,c);
                C += min(c,a+b);
            }
            cout<<min(min(A,B),C/2);
贪心贪心啊。。。。。。哎。。智商啊

首先我们要明白理想的情况是可以利用的鞋带有C双,总共由C/2对,也就是男生n/2,女生n/2,但是现在我们需要考虑现在到底是男生鞋不够还是女生鞋不够,所以我们比较

A和B,谁小就代表谁不够,那么就以这个为依据,A和B分别都是去最优的情况。。。。。。。。就是这样

感觉贪心和dp问题都要考脑子啊,,,,QAQ


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值