
基本算法题
文章平均质量分 70
coco_astrids
"Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart."
------Jobs
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
hud1003最大子序列和
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 52833 Accepted Submission(s): 11726 Problem Description Given a sequence原创 2016-08-11 10:47:45 · 317 阅读 · 0 评论 -
OUTOJ 简单的计算式(普通方法+队列法)
题目连接:http://115.28.203.224/problem.php?cid=1012&pid=6 解题思路: 因为题目要求,运算符只有+和*,所以,不需用栈或队列也能做出。 将数字和字母分别存到两个数组中,存字母好想,本题关键就是要想到如何存数字! 代码实现: #include #include #include #include #include原创 2016-11-26 17:11:05 · 376 阅读 · 0 评论 -
QUTOJ 飘飘和小石(简单搜索+暴力)
题目连接:http://115.28.203.224/problem.php?cid=1012&pid=2 解题思路: 如图所示,石凳是首尾相接的。从石凳1开始,按照题目要求走石凳。用暴力的方法,定义一个vis[]数组进行标记,如果遍历完发现存在没有走过的石凳,输出NO;否则YES。原创 2016-11-26 16:30:40 · 369 阅读 · 0 评论 -
HDU 2091----空心三角形
这个题比较难弄的点是:每一行最后一个字母后面没有空格。注意这个就比较好想了,唉,我弄了好几遍,苦啊~ 代码实现: #include int main() { int n; char s; int m = 0; while (1) { scanf("%c", &s); if (s == '@')原创 2016-11-25 15:45:31 · 287 阅读 · 0 评论 -
杨辉三角
解题思路及注意事项: 我的方法是: 定义一个数组,用两个for循环分别把所有1存入数组中和把除了1以外的数存入数组中。存入除了1以外的数时要注意for循环! 存入数不是很难想,但最关键的是输出的方式一定要看好: 1. 每一行数字之间有一个空格,但最后一个数后面没有空格。 2. 每一组输出后有一个空行。 代码实现: #include #include #include #原创 2016-11-25 13:59:03 · 395 阅读 · 0 评论 -
素数筛选法+记录给定范围内素数的个数(高效率)
当一个数不算大的时候,可以用普通的求素数的方法去求,但是如果一个数过大的话,就像让求1-十亿之间素数的个数,普通方法就不行了,这事就需要用到素数筛选法,他的时间复杂度是O(n),尽管不算很好,但是,也算是目前为止比较快的一种方法了,它是以空间换取时间,现在的计算机,空间有的是,但是时间是非常珍贵的。效率问题特别重要。他的原理就是标记,防止重复判断,这样提高了效率。就像2是素数,所有是2的倍数的肯定原创 2016-11-19 08:46:57 · 4898 阅读 · 2 评论 -
求最大公约数
先来看一下最大公约数的定义:最大公约数也成最大公因子,即两个或多个整数共有约数的最大的那个。 这里我们用到辗转相除法: 辗转相除法:辗转相除法是求两个自然数的最大公约数的一种方法,也叫欧几里德算法。 当两个数都较大时,采用辗转相除法比较方便. 其方法是: 以大数除以小数,如果能整除,那么小数就是所求的最大公约数.否则再用小数除以余数; 再用这新除法的余数去除刚才的余数.依此类推原创 2016-10-15 09:31:59 · 292 阅读 · 0 评论 -
Codeforces 50A(往矩形里填多米诺骨牌)
A. Domino piling time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a rectangular board of M × N原创 2016-09-21 22:01:24 · 1246 阅读 · 0 评论 -
Codeforces Round #360 A 简单模拟
A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Arya has n opponents in the school. Each day he原创 2016-09-05 20:10:34 · 389 阅读 · 0 评论 -
素数筛选法
HDU1397 Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conject原创 2016-08-31 22:44:27 · 375 阅读 · 0 评论 -
组合数+高效求最小公倍数
1. 组合数 题意:给出n个数, 从中取出m个数,一共有几种不同的组合方法? 例如,从4个数里面拿出2个数,一共有6种不同的方法。 代码实现: #include #include #include using namespace std; int form(int a, int b) { if (a < b) return 0; if (b == 0原创 2017-04-07 21:39:06 · 841 阅读 · 0 评论