Question:
Cao wants to be the smartest person. The first line of data is the number of his opponents, and the second is his IP address.
Then list the IP addresses of all opponents. If Cao wins a person higher than his IP address, his IP address will be added to 2; otherwise, the IP address will be added to 1.
And if Cao wins, ask Cao to win the highest IP Address
Solution:
The greedy idea is very simple. Sort the IP addresses of each competitor, and find the smallest IP address among the people whose IP address is higher than him.
In the end, there is no higher than his IP address, and the rest of the people will be defeated one by one, A for loop will be done
# Include <iostream> # include <algorithm> # include <cstdio> using namespace STD; int A [550]; int N, IP; int counter; int main () {While (~ Scanf ("% d", & N, & IP) {counter = 0; For (INT I = 0; I <n; I ++) {scanf ("% d", & A [I]) ;}sort (A, A + n); For (INT I = 0; I <n; I ++) {if (a [I]> ip) {counter ++; IP + = 2 ;}} printf ("% d \ n", IP + N-counter );} return 0 ;}