上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 66 下一页
摘要: 简单点说题目就是要求连个分数的最小公倍数,这个题目上次在参加比赛时遇到过,不过那时候是用很暴力的方法过的。本来上次我们已经推出来是求两个最简形式分数的分母的最小公倍数以及分母的最大公约数,不过就是A不掉,不过还好这次过掉了,方法论证是没错的。 对于两个最简的分数a / b, c / d 把他们两个的最小公倍数 x / y 也设为一个分数形式,那么这个 x 一定能够整除 a , c, y 一定能够被b , d整除。那么要求得最小公倍数,那么肯定是分子尽量小,即 a , c 的最小公倍数, 分母尽量大, 即 b , d 的最大公约数。 代码如下: 1 #include <stdio.h> 阅读全文
posted @ 2011-08-28 09:30 沐阳 阅读(1323) 评论(0) 推荐(0) 编辑
摘要: Distribute MessageTime Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 605Accepted Submission(s): 259Problem DescriptionThe contest’s message distribution is a big thing in prepare. Assuming N students stand in a row, from the row-head start transmit me 阅读全文
posted @ 2011-08-27 17:26 沐阳 阅读(424) 评论(0) 推荐(0) 编辑
摘要: 一个很朴素的问题,但是貌似以前没有接触到过,给定一个长度的棍子,现在要得到三种规格的棍子,每种若干条,问最少需要多少条长棍来分成三种棍子。 一开始用模拟,结果超时了,后面想想思路也是错的。这题应该是这样去考虑,现在想象我们是一个木匠师傅,现在要为客户来解决这个问题,当我拿到一根长为75的木棍时,我肯定要物尽其极,最大利用率的截断方式是 75 = 20 + 20 + 32 次之 为 75 = 20 + 20 + 28 , 再者为 75 = 20 + 20 + 20, 这时截成三段,当然还可以截成两段,这时组合方式就没有关系了,因为前面已经算完了所有组成三段的可能,也就不许要考虑剩余的多少问... 阅读全文
posted @ 2011-08-27 16:21 沐阳 阅读(275) 评论(0) 推荐(0) 编辑
摘要: 题目的意思求标号为1的点的最小可能的度,即在满足给定的条件下,如何连线能够使得连到1上的边尽可能的小。 由于题中要求 ① degree(i) != degree(j), (i != j, 1 <= i, j <= N). 所以每个点的度一定会是 1,2,3,4 ... N 分布,产生一个度为N的点,那么该点就要与其余N - 1个点以及标号为 “A”的点相连,一次这样的操作后,假设该次选择的点为X,那么N个点中除了 度为N的 X点,度为 1的与 X 相对的点 外,其余所有点的度均为 2,此时我们要选取出度为N-1的点,由于度为1的点(仅存的度为1的点)不能够改变它,所以下一步要在度为 阅读全文
posted @ 2011-08-27 14:41 沐阳 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 晚上果然是头昏脑涨,有点蛋蛋的忧伤啊。 该题讲的是一个交通系统,车票可以共享,即所有人坐车时,只要满足所有人加起来的时间比车票的总面值小就行,所以当有一个人要坐到更远的地方时,只要查看已经买的票是否够用,如果不够用就要增买车票。也即是车票能够满足后面的人能够到达这一站。 所以每次更新准则就是前面的车票总额能否使后面的人都到达下一站,如果能,花费不变,否则,花费为前面所述。 代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm&g 阅读全文
posted @ 2011-08-27 13:44 沐阳 阅读(312) 评论(0) 推荐(0) 编辑
摘要: 该题为简单的并查集应用,只要按要求把给定的关系合并起来,并在合并时遴选出最佳个数即可。 代码如下:#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace std;int set[100005];int cnt[100005];int max;inline int find( int x ){ return set[x]= x == set[x]? x: find( set[x] );}inline void merge( int x, 阅读全文
posted @ 2011-08-17 22:07 沐阳 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 1602: GCD depthTime Limit:1 SecMemory Limit:128 MBSubmit:24Solved:3[Submit][Status][Web Board]DescriptionIn mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), or highest common factor (hcf), of two or more non-zero integers, is the largest positive intege 阅读全文
posted @ 2011-08-17 17:25 沐阳 阅读(471) 评论(0) 推荐(0) 编辑
摘要: 给定一个IP要求判断是否为正确IP。这里用sscanf进行处理较为方便。在数据末尾添加一个tail字符来判定是否还有缀余字符,利用到该函数的返回值。 #include <cstdio>#include <cstring>#include <cstdlib>using namespace std;bool r( int x ){ return x>= 0&& x<= 255? 1: 0;}int main(){ char ip[105]; while( gets( ip ) ) { int a, b, c, d, len= strl 阅读全文
posted @ 2011-08-16 22:34 沐阳 阅读(473) 评论(2) 推荐(0) 编辑
摘要: 题义:给定一个数字串,求出这些串的第K小组合串。 代码如下:#include <cstdio>#include <algorithm>using namespace std;int num[1005];int main( ){ int N, M; while( scanf( "%d %d", &N, &M )!= EOF ) { for( int i= 1; i<= N; ++i ) { num[i]= i; } while( --M ) { next_permutation( num+ 1, num+ N+ 1 ); } fo 阅读全文
posted @ 2011-08-16 14:22 沐阳 阅读(284) 评论(0) 推荐(0) 编辑
摘要: BillboardTime Limit: 20000/8000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1619Accepted Submission(s): 809Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the 阅读全文
posted @ 2011-08-16 11:17 沐阳 阅读(589) 评论(0) 推荐(0) 编辑
上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 66 下一页