HDU 1058 Humble Numbers

BabbleDay posted @ 2013年8月02日 17:27 in 刷题防身 , 734 阅读

Humble Numbers

其实有时候动归用集合会让思路更简洁,但是时间会多一些。。

#include<iostream>
#include<set>
using namespace std;

int main()
{
    int f[4] = {2,3,5,7};
    set<long long> s;
    //set<int> ss;
    set<long long>::iterator it;
    s.clear();
    //ss.clear();
    s.insert(1);
    int count = 1;
    for(it = s.begin(); count <= 20000 && it!=s.end(); it++)
    {
        for(int i=0; i<4; i++)
        {
            s.insert(f[i] * (*it));
            count ++;
        }
    }
    int ans[5843]={0};
    int i = 0;
    for(it=s.begin(); i<=5842 && it!=s.end(); it++)
    {
        //    cout << *it << " | " ;
        ans[++i] = (*it);
    }
    //for(i=0; i<5843; i++) cout << ans[i] << " ";
    int n;
    while(cin >> n, n)
    {
        if(n%100==11 || n%100==12 || n%100==13)cout << "The "<< n << "th humble number is " << ans[n] << ".\n";
        else if(n%10==1) cout << "The "<< n << "st humble number is " << ans[n] << ".\n";
        else if(n%10==2) cout << "The "<< n << "nd humble number is " << ans[n] << ".\n";
        else if(n%10==3) cout << "The "<< n << "rd humble number is " << ans[n] << ".\n";
        else cout << "The "<< n << "th humble number is " << ans[n] << ".\n";
    }

    return 0;
}
Avatar_small
UP Board Question Pa 说:
2022年9月17日 21:09

Uttar Pradesh State Board of High School and Intermediate Education, Prayagraj Board and others have designed and suggested UP Board 6th Class Model Paper 2023 with Mock Test and Practice Questions for Term1 & Term 2 Exams of the Course. UP Board Question Paper Class 6 Every 6th Standard Student can download UP Board STD-6 Question Paper 2023 with Answers for All Languages and Subjects of the Course designed and suggested by the state leading subject experts for Self Practicing at home. Both SCERT & NCERT Syllabus Suggestions have introduced Set wide to of Hindi Medium, English Medium and Urdu Medium Students.

Avatar_small
WiFi Names 说:
2023年2月02日 23:34

Are you getting yourself a new WiFi router, then you might be happy because now you are able to set up your best WiFi names to your liking which is a funny act but a please to do indeed. WiFi Names Well as you already know that the reason why people be objective about finding the best WiFi names for their new connections or routers is that they want some cool or funny names that make them feel nice and at the same time when your friends, family.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter