H.Dance Floor | |||||
| |||||
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