摘要:题目:http://acm.timus.ru/problem.aspx?space=1&num=1748题意:求n范围内约数个数最多的那个数。Roughly speaking, for a number to be highly composite it has to have prime factors as small as possible, but not too many of the same. If we decompose a number n in prime factors like this:where are prime, and the exponents a
阅读全文
随笔分类 - algorithm
算法,程序的灵魂。
摘要:ural 1091 题目链接: http://acm.timus.ru/problem.aspx?space=1&num=1091题意是从1到n的集合里选出k个数,使得这些数满足gcd大于1解法:因子有2的数: 2,4,6,8,10,12,14.。。因子有3的数:3,6,9,12,15,18,21.。。因子有5的数:5,10,15,18,21,24.。。可以看出这里求出的集合时会有重复的,得去从。可惜没有学过容斥原理。不过解决这题还是没问题的。50以内的素因子有:2, 3, 5, 7, 11, 13, 17, 19, 23只有这些素因子才可能产生集合元素大于2的集合排除重复度为2的集合
阅读全文
摘要:题目链接: http://www.codeforces.com/problemset/problem/285/DPermutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length
阅读全文
摘要:题目链接: www.codeforces.com/problemset/problem/300/CVitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a
阅读全文
摘要:题目链接: http://acm.timus.ru/problem.aspx?space=1&num=1133problem description:is an infinite sequence of integers that satisfies to Fibonacci condition Fi+2=Fi+1+Fi for any integer i.Write a program, which calculates the value of Fn for the given values of Fi and Fj.InputThe input contains five int
阅读全文
摘要:如何快速求出区间范围[0,x]内的素数?Brute Force 总是那么的让人觉得亲近。枚举每一个数,判断该数是否为素数?bool isPrime( int x ) { if(x < 2) return 0; if(x == 2) return 1; for ( int i=2; i*i<=x; ++i ) if(0 == x%i) return 0; return 1;} // 用prime[0]存素数个数for ( int i=0; i<=x; ++i ) if( isPrime(i) ) prime[++prime[0] ] = i;暴力解决问题在很多...
阅读全文
摘要:编程之美这本书还是挺不错的,很多分析问题的方法都是让人受益的。算了废话什么的就不讲了。如何求解区间[x,y]内数字1出现的次数? 看看数据我就泪奔了。。。yy了一下就直接看解答了。这么这么长,烦人啊。还是自己想想吧!呵呵,果断会想数位DP啊。然后就写,debug。结束。找了oj提交? wa? wa?肿么回事呢?不会出错啊,写了个暴力的代码对拍,没有问题啊。正常数据,边界数据都测试过了。No Problem。给问题板块发了分报告。。。继续检查。。。算了吃饭去了。。。。回来又是debug,真心没错啊。。提交,编译中,测试中。。ac。这是哪门子事啊。 当时就有一种很坑的感觉,浪费了我一下午啊。我的解
阅读全文
摘要:The Stable Marriage ProblemDescriptionThe stable marriage problem consists of matching members of two different sets according to the member’s preferences for the other set’s members. The input for our problem consists of:a set M of n males;a set F of n females;for each male and female we have a lis
阅读全文
摘要:最小环问题:求个图中环路径代价最小的回路。如何求最小环?假如有 路径1->3->2,如果此时已经知道2-1的最短路径就好了。 回想下floyed的更新过程,就会发现更新第k次时,比k小的点之间都是最短距离的(要是点是联通的话)。所以给出解法:第k次更新图时,枚举和k相连的两条边。如 环路代价 = dist[i][k] + dist[k][j] + dist[j][i];求无向图中最小环的个数,先算出一个最小环代价,把之后算出的环代价与之对比更新就可以了。这个图中是求不同的最小环的个数,所以重边是没有影响的fzu 2090 http://acm.fzu.edu.cn/problem.
阅读全文
摘要:hdoj 1175http://acm.hdu.edu.cn/showproblem.php?pid=1175这题是简单的搜索,给图图中的两个位置,问这两个位置是否可以消去。有以下情况不能消去:1,起点和终点有任意一个是非法点,即不是图中的点;2,起点和终点有任意一个是数值为0的点,即该点事空的。3,起点和终点的数值不相同。4,起点和终点的最短距离大于2,这个最短距离是指转弯的次数。前3点都是直接可以处理的,对于第四点我是采用bfs搜的。记录当前节点的方向和转弯次数即可。在hdoj c++ 提交 跑了109ms, 弱啊 !View Code 1 // 用node记录上一次的方向,但是结束条件.
阅读全文
摘要:按位dp:对于当前长度i是枚举该为的值(0~10),统计出区间内合法的数;下面是基础入门的3题;hdoj 2089http://acm.hdu.edu.cn/showproblem.php?pid=2089区间数内不包含4和62的数的个数View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 8 int num[10][10]; 9 10 // 预处理长度为i
阅读全文
浙公网安备 33010602011771号