Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve in Java or C + + , thank you :) Farmer John has an important task - figuring out what type of hay
Please solve in Java or C thank you :)
Farmer John has an important task figuring out what type of hay to buy for his cows.
Farmer John's cows are numbered through and each cow likes exactly one type of hay
He wants all his cows to like the same type of hay.
To make this happen, Farmer John can host focus groups. A focus group consists of getting all cows in a contiguous range
numbered to inclusive, together for a meeting. If there is a type of hay that more than half the cows in the group like, then
after the focus group finishes meeting, all cows end up liking that type of hay. If no such type of hay exists, then no cows change
the type of hay they like. For example, in focus group consisting of a range of cows, or more of them would need to have the
same hay preference to cause the remaining cows to switch their preference to match.
Farmer John wants to know which types of hay can become liked by all cows simultaneously. He can only host one focus group
at a time, but he can run as many focus groups as necessary to get all cows to like the same type of hay.
INPUT FORMAT input arrives from the terminal stdin:
The first will consist of an integer denoting the number of independent test cases
The first line of each test case consists of
The second line consists of integers, the favorite types of hay for the cows in order.
It is guaranteed that the sum of over all test cases does not exceed
OUTPUT FORMAT print output to the terminal stdout:
Output lines, one line per test case.
If it possible to make all cows like the same type of hay simultaneously, output all possible such types of hay in increasing order.
Otherwise, output When printing a list of numbers on the same line, separate adjacent numbers with a space, and be sure
the line does not end with any extraneous spaces.
SAMPLE INPUT:
SAMPLE OUTPUT:
In the sample input, there are test cases.
In the first test case, it is only possible to make all cows like type FJ can do this by running a single focus group with all cows.
In the second test case, we can show that no cows will change which type of hay they like.
In the third test case, it is possible to make all cows like type by running three focus groups first by having cows through in
a focus group, then by having cows through in a focus group, then by having cows through in a focus group. By similar
logic, using cows through cows through then cows through we can make all cows like type
In the fourth test case, it is possible to make all cows like type by running a single focus group with all cows.
In the fifth test case, we can show that no cows will change which type of hay they like.
SCORING:
Input :
Inputs :
Inputs : for all
Inputs : No additional constraints.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started