zoukankan      html  css  js  c++  java
  • P1748 H数 题解

    CSDN同步

    原题链接

    简要题意:

    求第 (k) 个质因子只包含 (2,3,5,7) 的数。规定 (1) 是第一个这样的数。

    显然,本题可以用数组实现,用四个指针,将最小的往前进一发。

    但是,有 ( exttt{STL})这么弱的数据,我们还需要维护什么?

    你发现,需要去重和排序。这不就是 ( ext{set}) 的标本?

    每次取出 ( ext{set}) 第一个元素 (x),并将 (x imes 2,3,5,7) 均重新插入集合,同时将答案指针往后移一位。

    最后输出指针指向的值即可。

    时间复杂度:(O(n log n)).(( ext{set}) 它弄出来了一个 ( exttt{log})

    实际得分:(100pts).

    注:请注意判断 (0),否则只能得到 (94pts).

    #pragma GCC optimize(2)
    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    inline int read(){char ch=getchar();int f=1;while(ch<'0' || ch>'9') {if(ch=='-') f=-f; ch=getchar();}
    	int x=0;while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
    
    int main(){
    	int n=read(); set<ll> s;
    	if(!n) {puts("0");return 0;}
    	s.insert(1); set<ll>::iterator i=s.begin();
    	n--; //我们去掉1
    	while(n--) {
    		ll x=*i; //集合中第 i 小的 
    		s.insert(x*2); s.insert(x*3);
    		s.insert(x*5); s.insert(x*7);
    		i++; //指针后移
    	} printf("%lld
    ",*i);
    	return 0;
    }
    
    
  • 相关阅读:
    hdu 1715
    hdu 1370
    hdu 2370
    hdu 1393
    hdu 1564
    hdu 1720
    hdu 1342
    SQL技巧(sp_procedure_params_rowset,SQL中设置数据值为null)
    Control ‘dg’ of type 'GridView' must be placed inside a form tag with runat=server
    GridView事件中获取rowIndex值
  • 原文地址:https://www.cnblogs.com/bifanwen/p/12598729.html
Copyright © 2011-2022 走看看