HDU 1800 Flying to the Mars detailed hash

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.