usaco Chapter 3 section 3.1 Humble Numbers
来源:互联网 发布:网络构建师 编辑:程序博客网 时间:2024/05/17 03:16
/*
ID: niepeng1
LANG: C++
TASK:humble
*/
/*
For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all numbers whose prime factors are a subset of S. This set contains, for example, p1, p1p2, p1p1, and p1p2p3 (among others). This is the set of `humble numbers' for the input set S. Note: The number 1 is explicitly declared not to be a humble number.
Your job is to find the Nth humble number for a given set S. Long integers (signed 32-bit) will be adequate for all solutions.
*/
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#define Max1 100010
#define MaxK 110
using namespace std;
int prime[MaxK];
int pindex[MaxK]={0};
long int way[Max1];
int main()
{
FILE *in,*out;
in=fopen("humble.in","r");
out=fopen("humble.out","w");
int i,j,K,N,min,minindex;
fscanf(in,"%d %d",&K,&N);
for(i=0;i<K;i++)
fscanf(in,"%d",&prime[i]);
j=0;
way[j]=1;
while(j<=N)
{
min=0x7fffffff;
minindex=0;
for(i=0;i<K;i++)
{
while( double(way[pindex[i]])*prime[i] <= way[j])
{
pindex[i]++;
}
if(min>double(way[pindex[i]])*prime[i])
{
min=double(way[pindex[i]])*prime[i];
minindex=i;
}
}
pindex[minindex]++;
way[++j]=min;
}
fprintf(out,"%d/n",way[N]);
return 0;
}
- usaco Chapter 3 section 3.1 Humble Numbers
- USACO Section 3.1 Humble Numbers
- USACO Section 3.1 Humble Numbers
- USACO section 3.1 Humble Numbers(DP)
- USACO-Section 3.1-PROB Humble Numbers
- USACO-Section 3.1 Humble Numbers(DP)
- USACO 3.1.3 Humble Numbers
- USACO 3.1 Humble Numbers (humble)
- USACO 3.1 Humble Numbers
- USACO 3.1 humble numbers
- USACO 3.1 Humble Numbers
- USACO--3.1Humble Numbers
- USACO 3.1 Humble Numbers
- usaco 3.1 Humble Numbers
- USACO 3.1.3 Humble Numbers 丑数
- usaco Chapter 3 section 3.1 Agri-Net
- usaco Chapter 3 section 3.1 Score Inflation
- usaco Chapter 3 section 3.1 Shaping Regions
- James写的CodeSmith模板(二)
- Madwifi无线发送数据过程
- 李现路:在DSP6000中怎样编写您的第一个程序(二)
- 李现路:MTK开发中怎么建立一个独立的模块
- 李现路:DSP6000中C/C++语言和汇编语言的混合编程的方法
- usaco Chapter 3 section 3.1 Humble Numbers
- ORA-02243: ALTER INDEX 或 ALTER MATERIALIZED VIEW 选项无效
- 李现路:在DSP6000中怎样编写您的第一个程序(1)
- java生成doc html
- MySQL最多能装多少记录
- Opencv之PCA篇
- usaco Chapter 3 section 3.1 Score Inflation
- 个人职业提升需要跨越性思维
- 短信 男人女人