USACO section 3.1 Humble Numbers(DP)

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情
Humble Numbers

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.

PROGRAM NAME: humble

INPUT FORMAT

 

Line 1:Two space separated integers: K and N, 1 <= K <=100 and 1 <= N <= 100,000.
Line 2:K space separated positive integers that comprise the set S.

SAMPLE INPUT (file humble.in)

4 19
2 3 5 7

OUTPUT FORMAT

The Nth humble number from set S printed alone on a line.

SAMPLE OUTPUT (file humble.out)

27

思路:如果已知前n个丑数要求第n+1个,就只要把集合中的素数依次乘上前n个丑数找到大于第n个丑数的最小的数即是第n+1个丑数;

         不过要是这样直接写绝对爆。优化:用个数组num[];存第i个素数遍历到了第几个丑数,下次只要接着走就行了。

失误点:答案有大于1e9的数,所以const oo=1e9;会错,就是这个提交WA了一次,要用1e10; 

具体看代码:

 

/*
ID:nealgav1
LANG:C++
PROG:humble
*/
#include<fstream>
#include<cstring>
using namespace std;
ifstream cin("humble.in");
ofstream cout("humble.out");
const int oo=1e10;
const int mm=101000;
const int nn=110;
int prime[nn],num[mm],pos[nn];
int main()
{ int m,n;
  cin>>m>>n;
  memset(num,1,sizeof(num));
  memset(pos,0,sizeof(pos));
  for(int i=0;i<m;i++)
  cin>>prime[i];
  int Max,k,last,mid;
  num[0]=1;
  for(int j=1;j<=n;j++)
  { num[j]=oo;//cout<<Max<<"\n";
    for(int i=0;i<m;i++)
    {  for(int l=0;pos[i]<=j;l++)
       {
         mid=prime[i]*num[pos[i]];
         if(num[j-1]>=mid)pos[i]++;
         else break;
       }
       if(num[j-1]<mid)
       { if(num[j]>mid)
         {num[j]=mid;k=i;}

       }
    }pos[k]++;
  }
  cout<<num[n]<<"\n";
}


 

Humble Numbers
Russ Cox

We compute the first n humble numbers in the "hum" array. For simplicity of implementation, we treat 1 as a humble number, and adjust accordingly.

Once we have the first k humble numbers and want to compute the k+1st, we do the following:

	for each prime p
		find the minimum humble number h
		  such that h * p is bigger than the last humble number.

	take the smallest h * p found: that's the next humble number.

To speed up the search, we keep an index "pindex" of what h is for each prime, and start there rather than at the beginning of the list.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>

#define MAXPRIME 100
#define MAXN 100000

long hum[MAXN+1];
int nhum;

int prime[MAXPRIME];
int pindex[MAXPRIME];
int nprime;

void
main(void)
{
    FILE *fin, *fout;
    int i, minp;
    long min;
    int n;

    fin = fopen("humble.in", "r");
    fout = fopen("humble.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d %d", &nprime, &n);
    for(i=0; i<nprime; i++)
	fscanf(fin, "%d", &prime[i]);

    hum[nhum++] = 1;
    for(i=0; i<nprime; i++)
	pindex[i] = 0;

    while(nhum < n+1) {
	min = 0x7FFFFFFF;
	minp = -1;
	for(i=0; i<nprime; i++) {
	    while((double)prime[i] * hum[pindex[i]] <= hum[nhum-1]) 
		pindex[i]++;

	    /* double to avoid overflow problems */
	    if((double)prime[i] * hum[pindex[i]] < min) {
		min = prime[i] * hum[pindex[i]];
		minp = i;
	    }
	}

	hum[nhum++] = min;
	pindex[minp]++;
    }

    fprintf(fout, "%d\n", hum[n]);
    exit(0);
}
 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: humble
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3752 KB]
   Test 2: TEST OK [0.000 secs, 3752 KB]
   Test 3: TEST OK [0.000 secs, 3752 KB]
   Test 4: TEST OK [0.000 secs, 3752 KB]
   Test 5: TEST OK [0.011 secs, 3752 KB]
   Test 6: TEST OK [0.032 secs, 3752 KB]
   Test 7: TEST OK [0.011 secs, 3752 KB]
   Test 8: TEST OK [0.011 secs, 3752 KB]
   Test 9: TEST OK [0.000 secs, 3752 KB]
   Test 10: TEST OK [0.000 secs, 3752 KB]
   Test 11: TEST OK [0.000 secs, 3752 KB]
   Test 12: TEST OK [0.086 secs, 3752 KB]

All tests OK.

Your program ('humble') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
2 7
3 5
------- test 2 ----
4 19
2 3 5 7
------- test 3 ----
1 20
2
------- test 4 ----
6 10000
2 3 5 7 11 13
------- test 5 ----
6 25000
2 3 5 7 11 13
------- test 6 ----
8 100000
2 3 5 7 11 13 17 19
------- test 7 ----
7 30000
2 3 5 7 11 17 23
------- test 8 ----
7 28888
2 3 5 11 17 23 31
------- test 9 ----
1 30
2
------- test 10 ----
4 300
11 17 23 31
------- test 11 ----
5 300
11 17 19 23 31
------- test 12 ----
100 100000
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541

 

基于MATLAB的电池等效电路模型(ECM)仿真,用于分析电气行为和动态响应.zip 1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 立即下载

相关推荐

隔离型全桥LLC谐振变化器建模及参数设计资料【仿真+设计报告+计算书】

内容概要:本文档系统性地提供了隔离型全桥LLC谐振变换器的建模、仿真与参数设计全套技术资料,涵盖Simulink/Plecs仿真模型、详细设计报告及Mathcad计算书,内容涉及开环与闭环控制、软启动过程、恒压恒流双闭环竞争控制等多种工况。资料还拓展至多相交错LLC、双向CLLC拓扑以及V2G(Vehicle-to-Grid)电动汽车充放电等前沿应用场景,并融合状态估计算法(如卡尔曼滤波、扩展卡尔曼滤波、粒子滤波)与神经网络技术进行系统性能优化,配套PPT说明与高水平EI期刊复现案例,为电力电子领域的科研与工程设计提供完整的技术支撑; 适合人群:适用于电力电子、电气工程及其自动化等相关专业的高校研究生、科研人员,以及从事高频DC-DC变换器、新能源电源系统开发的工程师,具备扎实电路理论基础和Matlab/Simulink仿真能力者尤佳; 使用场景及目标:①支撑LLC谐振变换器相关的科研课题、学位论文或项目开发;②开展高频高效电源的参数设计、效率优化与动态响应分析;③学习并复现高水平期刊中先进的控制策略,如变频控制、混合移相控制及智能优化算法;④掌握Simulink/Matlab在电力电子系统建模、控制算法实现与状态估计中的综合应用; 阅读建议:建议结合仿真模型、Mathcad计算书与设计报告三位一体同步研习,重点理解主电路参数设计与闭环控制逻辑之间的耦合关系,优先运行典型算例并调试关键模块,有条件者可进一步推进至硬件原型验证,并积极探索状态估计与人工智能算法在电力系统动态建模中的融合应用。

USACO-Section 3.1 Humble Numbers(DP)

以前貌似做过类似的一题(hdu-1058),不过只有2,3,5,7四个数字,是这题的简化版 第一反应是用优先队列,每次取队首元素乘以每个素数,压入队列,但这样很可能会MLE 依旧是官方题解:对于每一个质数p,找到最小的丑数h使得p*h大于dp[i-1],取最小的h*p,即为dp[i],为了减少计算,可以用indx[j]表示质数j已经计算到哪一个丑数

idealism_xxm的专栏 489

在 Ansys Mechanical 中使用“螺栓工具”插件自动生成螺栓

在有限元分析 (FEA) 中,高效创建螺栓连接对于确保机械装配的结构完整性和性能至关重要。螺栓是连接组件不可或缺的一部分,它们在负载下的精确建模会影响整个系统。快速高效的螺栓建模使工程师能够快速优化设计,满足紧迫的期限,并通过为其他关键设计任务释放资源来提高整体生产力。此外,螺栓建模的精度可以最大限度地降低模型创建过程中出错的风险,这对于获得可靠和准确的分析结果至关重要。因此,在 FEA 中快速且无错误地创建螺栓连接对于高效、可靠和成功的工程结果至关重要。

jkh920184196的博客 3101

USACO SECTION 3.1 Humble Numbers

Humble Numbers 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, a

313

Excel数字变成了小数点+E+17?这些方法帮你解决!

本文介绍了三种解决Excel中数字变成小数点+E+17问题的方法:通过下拉箭头或右键菜单设置单元格格式为文本、使用TEXT函数将科学计数法转换为文本。这些方法各有优缺点,适用于不同的场景和需求。在实际应用中,我们可以根据具体情况选择合适的方法来解决问题。通过以上方法,我们可以轻松地从繁琐的小数点+E+17问题中解脱出来,更便捷地处理Excel中的数字。希望本文能够帮助到您,让您在使用Excel时更加得心应手!

nntxthml的博客 1246

计算机组成原理课设

计算机组成原理课程设计

qq_63306482的博客 8054

USACO section 3.1 Contact(AC自动机)

Contact IOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right f

nealgavin的专栏 9384

TDR阻抗会爬坡? 别担心,不是你的错,你只是不够了解TDR!

TDR除了可以单靠一个Port就得到通道的阻抗外,其实也可以拿来计算传输线的Delay,或是两两对象之间的距离,甚至是拿来求得等效介电常数!

jkh920184196的博客 2159

USCAO section 1.3 Calf Flac

Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes

nealgavin的专栏 6656

Mumax3高效模拟技巧:如何利用代码模板快速完成磁性材料特性分析

本文介绍了利用Mumax3代码模板库提升磁性材料微磁学模拟效率的核心方法。通过构建模块化的环境配置、材料库和特征长度计算模板,研究者可以快速组装模拟方案,自动化参数扫描与结果分析,从而将精力聚焦于物理问题本身,实现工作效率的指数级提升。

zz67890的博客 550

基于深度学习卷积神经网络的医学图像乳腺癌分类

一、项目背景与意义乳腺癌是女性最常见的恶性肿瘤之一,其早期发现和治疗对于提高患者的生存率和生活质量至关重要。然而,乳腺癌的诊断通常依赖于医生的经验和主观判断,这不仅耗时而且可能存在误差。近年来,深度学习技术特别是卷积神经网络(CNN)在图像处理领域取得了显著进展,为乳腺癌的自动分类提供了新的解决方案。本项目旨在利用深度学习卷积神经网络构建一套高效、准确的医学图像乳腺癌分类系统,辅助医生进行乳腺癌的早期诊断和治疗。二、技术实现。

2301_79810943的博客 976

USACO section 1.5 Checker Challenge(dfs深搜)

Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more tha

nealgavin的专栏 1922

单片机设计具备断电记忆功能的计时器

本文介绍了如何设计一款具备断电记忆功能的计时器,利用单片机和EEPROM存储器实现了计时器值的保存和恢复。当然,在实际的设计中还需要考虑其他因素,如电源管理、时钟精度等,以确保计时器的正常运行和准确性。选择合适的单片机:在设计计时器时,我们需要选择一款具备存储功能的单片机,以便在断电后能够保存计时器的状态。可以优化显示方式,使用更加直观的界面来展示计时器的值;函数中,我们首先从 EEPROM 中读取计时器的初始值,然后在一个无限循环中每秒钟增加计时器的值,并将新的值写入 EEPROM 中。

RlDart的博客 1094

USACO section 2.3 Longest Prefix(dp)

Longest Prefix IOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in

nealgavin的专栏 1486

通过理解 sk_buff 深入掌握 Linux 内核自定义协议族的开发实现

在。

数字人生 458

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

USACO section 2.4 Cow Tours(并查集+最短路)

Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pasture

nealgavin的专栏 1405

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

USACO section3.1 Shaping Regions(漂浮法)

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the s

nealgavin的专栏 1052

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

USACO section 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

nealgavin的专栏 989

USACO section 3.1 Stamps(dp)

Stamps Given a set of N stamp values (e.g., {1 cent, 3 cents}) and an upper limit K to the number of stamps that can fit on an envelope, calculate the largest unbroken list of postages from 1 cent

nealgavin的专栏 980

USCAO section 4.1 Fence Loops(最短路,最小环,5级)

Fence Loops The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only a

nealgavin的专栏 941

USACO section 1.5 Superprime Rib(深搜)

Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer John

nealgavin的专栏 937

USACO section 2.2 Party Lamps

Party Lamps IOI 98 To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored lamps numbered from 1 to N. The lamps are connected to four buttons: Button 1: Wh

nealgavin的专栏 913

USACO section 3.2 Spinning Wheels(模拟)

Spinning Wheels 1998 ACM NE Regionals Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an ali

nealgavin的专栏 875

USCAO section Mother's Milk(搜索)

Mother's Milk Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty

nealgavin的专栏 847

USACO section 3.2 Feed Ratios(高斯定理)

Feed Ratios 1998 ACM Finals, Dan Adkins Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of th

nealgavin的专栏 803
上一篇: USACO section 3.1 Score Inflation(DP背包)
下一篇: USACO section3.1 Shaping Regions(漂浮法)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值