Connection Status:
Competition Arena > Chopsticks
SRM 570 · 2012-12-13 · by snuke · Greedy
Class Name: Chopsticks
Return Type: int
Method Name: getmax
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Cat Carol wants to invite some of her friends to a lunch at her house. Carol has some chopsticks of possibly different lengths. Each of the invited guests must receive two chopsticks. Additionally, the two chopsticks given to each guest must have exactly the same length.


You are given a int[] length. Each element of length is the length of one of Carol's chopsticks. Compute and return the maximum number of friends Carol may invite.

Constraints

  • length will contain between 1 and 50 elements, inclusive.
  • Each element of length will be between 1 and 100, inclusive.
Examples
0)
{5,5}
Returns: 1

Two chopsticks have the same length. Carol can invite one friend.

1)
{1,2,3,2,1,2,3,2,1}
Returns: 4

Carol can make one pair of chopsticks of length 1, two pairs of chopsticks of length 2, and one pair of chopsticks of length 3. She can invite four guests in total.

2)
{1}
Returns: 0

Carol has only one chopstick. Carol can't invite anybody.

3)
{1,2,3,4,5,6,7,8,9}
Returns: 0

No two chopsticks have the same length. Carol can't invite anybody.

4)
{1,1,2,3,5,8,13,21,34,55,89}
Returns: 1

Submissions are judged against all 79 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Chopsticks with a public method int getmax(vector<int> length) · 79 test cases · 2 s / 256 MB per case

Submitting as anonymous