UVA 1575 Factors】的更多相关文章

https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 给出n,求最小的k 搜索 从最小的质数开始枚举选几个 假设前i-1个种质数用了k个,有sum种方案,第i种质数选a个, 那么前i种质数的方案就有sum*C[k+a][a] 可以理解原来有k个位置,又加了a个位置,有a个数可以放在任意位置 所以前i种的每一种方案都变成C[k+a][a]种 枚举每个质…
 Factors and Factorials  The factorial of a number N (written N!) is defined as the product of all the integers from 1 to N. It is often defined recursively as follows: Factorials grow very rapidly--5! = 120, 10! = 3,628,800. One way of specifying su…
我一开始以为有什么很牛逼的方法来做,然后一直没有思路 后来看了https://blog.csdn.net/zju2016/article/details/78562932的博客 竟然是暴搜???????????/ 好我服了 大致思路:素数的范围在100以内 因为要求尽量小,所以素数取得要尽量小 在100内的素数有20多个,这20多个配合上幂 是可以凑到2的63次方那么大的 那么我们枚举素数,得出的组合个数再与题目给的比较 然后这里有个贪心,因为要尽量小,所以素数小的要取多一些 大的取小一些,所以…
Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in a positive integer.InputThe input tests will consist of a series of positive integers. Each number is on a line on its own. Themaximum value is 100000…
 Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the contestants are tested on their ability to recall a seque…
题目:输出n!中素数因数的个数. 分析:数论.这里使用欧拉筛法计算素数,在计算过程中求解就可以. 传统筛法是利用每一个素数,筛掉自己的整数倍: 欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数: 所以每一个前驱的素椅子个数一定比当前数的素因子个数少一个. 说明:重新用了"线性筛法". #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring&g…
称号:发现没有比给定数量少n的.只要2,3一个因素的数字组成. 分析:数论.贪婪,分而治之. 用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}. 然后.每取两个指针相应元素*2和*3的值中最小的即为未找到的数字中最小的: 注意,可能生成反复数据.不要存进去(反复数据.一定连续产生). 说明:打表计算.二分查询输出就可以. #include <iostream> #include <cstdlib> #include <cstdio> using n…
题目大意:Euler's Totient的应用. 几乎和UVa 10179 - Irreducable Basic Fractions一样,于是偷了个懒,直接用10179题的代码,结果WA了,感觉一样啊...然后就搜,看到n=1的特殊情况,好吧,读题的时候也小小注意了一下"less than" 呢,写代码时就忘的一干二净了...读题时应该把注意事项记下来的... #include <cstdio> #include <vector> #include <a…
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included.Write a program to find and print the 1500'th ugly number. Input There…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5…
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径. f[i][j][k]从下往上到第i层第j个和为k的方案数 上下转移不一样,分开处理 没必要判断走出沙漏 打印方案倒着找下去行了,尽量往左走   沙茶的忘注释掉文件WA好多次   #include <iostream> #include <cstdio> #include <a…
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求LCS,转移同时维护f[i][j].s为当前状态字典序最小最优解 f[n][n].s的前半部分一定是回文串的前半部分(想想就行了) 当s的长度为奇时要多输出一个(因为这样长度+1,并且字典序保证最小(如axyzb  bzyxa,就是axb|||不全是回文串的原因是后半部分的字典序回文串可能不是最小,多…
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问题 |00|+|01|=|0| 注意序列是环形 // // main.cpp // poj3869 // // Created by Candy on 25/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <i…
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 // // Created by Candy on 24/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cst…
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll…
UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这次转移会给其他的元素带来的代价,也就是转移前已经出现但还没结束的元素都会代价+1   预处理每种颜色在两个序列中出现的位置bg[i][0/1]和ed[i][0/1], 计算f[i][j]时同时计算w[i][j]为(i,j)这个状态已经出现还没结束的个数 注意bg要先初始化为INF,计算w: if(b…
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4053   Accepted: 1318 Description The binomial coefficient C(m,n) is defined as m! C(m,n) = -------- n!(m-n)! Given four natural numbers p, q…
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is the same written forwards and backwards. For example, ‘racecar’ is a palindrome, but ‘fastcar’ is not. A partition of a sequence of characters is a lis…
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After several thrilling events we find her in the first station of Algorithms City Metro, examining the time table. The Algorit…
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to the following restrictions The i-th rook can only be placed within the rectan- gle given by its left-upper corner (xli,yli) and its right- lower corner…
UVA - 11987 Almost Union-Find I hope you know the beautiful Union-Find structure. In this problem, you’re to implement something similar, but not identical. The data structure you need to write is also a collection of disjoint sets, supporting 3 oper…
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]); CODE: BZ: /*================================================================= # Created time: 2016-03-28 21:10 # Filename: uva4394.cpp # Desc…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 147 - Dollars Time limit: 3.000 seconds Dollars New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and…
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=243 uva开头描述: 307 - Sticks Time limit: 3.000 seconds hduoj 开头描述: E - Sticks Time Limit:3000MS     Memo…
题目链接:https://uva.onlinejudge.org/external/16/1630.pdf 题意:折叠串,给一个字符串,相同部分可以折叠,折叠可以嵌套.求最短长度的一种折叠方法.括号和数字的长度也要考虑进去. 刚看到这个题目,没有一点思路,还是大牛们厉害! 分析:一个串,可以转成两种形式,要么本身可以转成有重叠部分的串,要么分成两个部分,再转成有重叠部分的串. 本身是否是重叠串,利用kmp查,分成两个部分,遍历一遍所有情况,这样,dp顺序就出来了,最外层是每次查的长度,第二层就是…
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能从一端选取. 并且A B都尽力使自己选择的结果为最大的,可以理解成A B每一步走的都是最优的. 如果A先选择,则A B差值最大是多少. 分析: 总和是一定的,所以一个得分越高,另一个人的得分越低.当前状态总是最开始的状态的一个子状态. d(i,j): 先手取 i ~ j 最优策略下,得分最大值. d…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515 http://7xjob4.com1.z0.glb.clouddn.com/c6a2a6f54f5a6c2cae2c82df2ec552f7 题意:填已有字母的格子,使相邻格子字母不同,使字典序尽量小 思路:从小到大排,检验是否可行 #include <bits/stdc++.…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1736 http://7xjob4.com1.z0.glb.clouddn.com/c2dd6437bf7bef120bf27475f3097822 题意:至少多少步将当前局面状态移动后到指定局面状态 思路:先考虑最大的那个盘子,将它移到最终位置,那么参考局面为其中一个柱子为空,一个为只有最…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2379 http://7xjob4.com1.z0.glb.clouddn.com/33af24c925ae62df4c094b22a2ba7e37 题意:给定1-n的数,可选多个数减去同一整数,求最小的操作次数 思路:保留1~n/2,剩下全减去n/2+1,得1,2...,n/2,0,1,.…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2151 http://7xjob4.com1.z0.glb.clouddn.com/f1186ae9a93d903ab533e5fce524bac6 题意:给你一副手牌,输出这手牌所有的听牌 思路:枚举所有34种牌,依次判断是否听这牌,先枚举选出将,再枚举顺子.刻子等,递归判断. #incl…