UVA10273 - Eat or Not to Eat?(暴力)
题目链接
题目大意:一个农场的主人为了改善收入决定每天要将产量最少的那一头牛杀掉,但是如果这一天出现了多只产量最小的牛,那么这一天一头也不杀。然后给你n头牛,给你每头牛的产量周期和周期内的产量,问多少天后可以确定剩余的牛的情况。
解题思路:求出这n头牛的周期的最小公倍数,那么在这个周期内,如果没有牛被杀的话,那么...
分类:
其他好文 时间:
2014-09-23 16:28:24
阅读次数:
236
6,求最大公约数和最小公倍数 import java.util.Scanner; public class HCFandLCM { public static void main(String[] args) { int a, b, m; Scanner scanner = new Scanner(...
分类:
其他好文 时间:
2014-09-22 17:34:02
阅读次数:
155
题目:从1~n去若干个数字,使得他们的最小公倍数不小于M的有多少种。
分析:dp,数论,搜索。其实就是一个背包类似物。(貌似离散化dp写起来很简洁)
由于每个素数因子的个数有限(不超过20个)直接打表(dfs)计算出所有的最小公倍数;
然后DP更行最小公倍数即可;
这个题目要做一些优化(囧,TLE一次):
...
分类:
其他好文 时间:
2014-09-20 14:07:47
阅读次数:
248
分解质因数求最大公约数求最小公倍数牛顿迭代求平方根分解质因数import java.util.ArrayList;import java.util.List;public class Solution { // 返回质因数分解 List getPrimeFactors(int n) { ...
分类:
其他好文 时间:
2014-09-17 18:19:42
阅读次数:
241
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。def foo(a,b): if a<b: (a,b)=(b,a) aa=a; bb=b; while b!=0: tmp=a%b; a=b; b=tmp; ...
分类:
编程语言 时间:
2014-09-13 09:21:14
阅读次数:
198
最小公倍数Time Limit: 0 ms Case Time Limit: 0 ms Memory Limit: 0 KBSubmit: 17 Accepted: 1 This problem will be judged on SCU. Original ID: 1630...
分类:
其他好文 时间:
2014-09-07 13:26:35
阅读次数:
197
题目链接
题意:给你两个数G和L,输出两个正整数,最大公约数为G,最小公倍数为L,输出a最小的情况,如果不存在输出-1。
思路:当a最小时,a = G,所以只要L % G == 0,就表示存在。
代码:
#include
#include
#include
#include
using namespace std;
int g, l;
int main...
分类:
其他好文 时间:
2014-09-06 17:25:33
阅读次数:
288
//问最少置换多少次变成有序序列
//每个位置都有个循环节 求全部位置循环节的最小公倍数
# include
# include
# include
using namespace std;
int gcd(int x,int y)
{
if(y==0)
return x;
return gcd(y,x%y);
}
int lcm(int x,int y)
{...
分类:
其他好文 时间:
2014-09-02 15:51:04
阅读次数:
223
必须MARK下:任何时候都要保持清醒头脑,不要被题目绕了。。其实就是求最小公倍数。#include #include #include using namespace std;__int64 v[20];__int64 gcd(__int64 a,__int64 b){ if(b==0) retur...
分类:
其他好文 时间:
2014-09-01 12:32:43
阅读次数:
204
懒癌发作的时候需要做做水题。
GCD+LCM 辗转相除求出GCD,然后再LCM。
int gcd(int a,int b)
{
int r=0;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
如例子 10 14
10%14=10;a=14,r=...
分类:
其他好文 时间:
2014-09-01 10:45:12
阅读次数:
238