Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1800
This topic is Dhahashi's simple question, the main difficulty lies in how to abstract the question painting.
For each set of data, I require a minimum of a few brooms.
We sort 2 4 5 6 4 for this set of inputs, become 2 4 4 5 6, each time take the longest increment sequence, take the number of times is the answer we need, please think carefully, if the input is 2 4 5 6, then we only need a broom to install everyone, but we enter 2 4 4 5 6, we need two, we each have taken an increment sequence, why do we start with one, and now we need two? Because I also have a person's rank is also 4, and I already have a 4 and the sequence must increment, so the same level of 4 I can only take one person. The other had to keep the next time to fetch. So the question is abstract: Ask for the number of times the most frequent occurrence of a set of numbers!
Is it easy to think like this?
Each time you enter a number I, the array mp[i]++ once, then the scope of I all over again, the MP array of the largest element output on the line. (If you do not know the map inside the STL can own Baidu a bit)
Put in a complete code:
#include <iostream> #include <string> #include <stdio.h> #include <map>using namespace Std;int Main () { int n,max; map<int,int>mp; int num; while (scanf ("%d", &n)!=eof) { mp.clear (); max=0; while (n--) { scanf ("%d", &num); mp[num]++; if (Mp[num]>max) { max=mp[num]; } } printf ("%d\n", max); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1800 Flying to the Mars detailed hash