HDU 1058 Priority Queue or heap

Source: Internet
Author: User

It should be a priority queue or a pile of questions because each number should be the number that has been obtained, but the 2*7 is greater than the 3*2, it must be guaranteed that every acquisition is not *7 the smallest number

But it actively reduced the difficulty in the sample to sell a Moe N range is 1~5842 and the No. 5842 in the example is given. So when we take out a number and find out how it's going to be *7, make a judgment if it's bigger than the last one. Because the order of multiplication can save a little time

It is not possible to open a large vis array when judging whether a number has occurred, so the direct for loop is not timed out from the ANS array qaq

In particular, it is not difficult to think about the problem, but the output of the English usage is pit

1 2 3 are first second third so the abbreviation is St nd Rd

21 22 23 etc are Twenty-first Twenty-second twenty-third and so their abbreviations are St nd Rd

But 11 12 13 is not. Their first abbreviations are th.

(My output code is very cumbersome to write.) Because I'm too lazy to change. )

#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h > #include <queue> #include <iostream>using namespace std;long long int e[6050];int W;bool find (Long long    int x) {for (int i=0;i<w;i++) {if (e[i]==x) return true; } return false;}    void Init () {w=0;    Queue<long Long int >q;    Q.push (2);    Q.push (3);    Q.push (5);    Q.push (7);   E[w++]=1;    e[w++]=2;e[w++]=3;e[w++]=5;e[w++]=7;       while (!q.empty ()) {Long long int z=q.front (); Q.pop ();            /* if (w==5842) return; */for (int i=0;i<4;i++) {long long int x=z;            if (x> 2000000000) continue;                if (i==0) {x*=2;                if (x> 2000000000) break;                    if (!find (x)) {e[w++]=x;                Q.push (x);       }} else if (i==1) {         x*=3;                if (x> 2000000000) break;                    if (!find (x)) {e[w++]=x;                Q.push (x);                }} else if (i==2) {x*=5;                if (x> 2000000000) break;                    if (!find (x)) {e[w++]=x;                Q.push (x);                }} else if (i==3) {x*=7;                if (x> 2000000000) break;                    if (!find (x)) {e[w++]=x;                Q.push (x);    }}}}}int main () {init (), int n;sort (E,E+W), while (~SCANF ("%d", &n)) {if (n==0) break;    if (n==11) printf ("The 11th humble number is");    else if (n==12) printf ("The 12th humble number is");    else if (n==13) printf ("The 13th humble number is");       else { if (n%10!=1&&n%10!=2&&n%10!=3) {printf ("The%dth humble number is", n);        } else if (n%10==1&&n%100!=11) {printf ("The%DST humble number is", n);        } else if (n%10==2&&n%100!=12) {printf ("The%DND humble number is", n);        } else if (n%10==3&&n%100!=13) {printf ("The%DRD humble number is", n);    } else printf ("The%dth humble number is", n); } printf ("%i64d.\n", E[n-1]);}}

  

HDU 1058 Priority Queue or heap

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.