题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299
题目大意:就是给你一个n,求1/x+//y=1/n正整数解的个数。
思路:首先我们可以在两边同时乘以xyn得yn+xn=xy,然后因式分解的(x-n)*(y-n)=n*n。这题要求解的个数,就变成了求n*n的因子数,网上很多人都是令y=n+k,然后的x=(n*n)/k+n,这儿也是求n*n的...
分类:
其他好文 时间:
2014-07-27 11:13:22
阅读次数:
242
题目:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtim....
分类:
编程语言 时间:
2014-07-27 10:46:02
阅读次数:
294
题目:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime comp....
分类:
编程语言 时间:
2014-07-27 10:43:42
阅读次数:
239
题意:给你一个传递闭包的矩阵,mp[u][v] = 1表示u可以到达v,为0代表不可到达,问你至少需要多少条边组成的传递闭包符合这个矩阵给出的关系分析:考虑一个强连通分量,如果这个分量有n个节点,那么至少只需要n条边皆可以满足传递闭包(因为此时形成环就可),所以求出所有的强连通分量,将他们缩成一个个...
分类:
其他好文 时间:
2014-07-27 10:15:32
阅读次数:
217
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:
其他好文 时间:
2014-07-27 09:49:52
阅读次数:
237
1.代码:/**** Secure Hash Algorithm (SHA1)* http://www.webtoolkit.info/***/function SHA1 (msg) { function rotate_left(n,s) { var t4 = ( n>>(32-s)); ...
分类:
编程语言 时间:
2014-07-27 09:38:22
阅读次数:
340
很久之前就想攻克一下网络流的问题了,一直拖着,一是觉得这部分的内容好像非常高级,二是还有很多其他算法也需要学习,三是觉得先补补相关算法会好点
不过其实这虽然是图论比较高级的内容,但是基础打好了,那么还是不会太难的,而且它的相关算法并不多,熟悉图论之后就可以学习了,就算法不会二分图也可以学习。
这里使用Ford-Fulkerson算法,其实现的方法叫做:Edmonds-Karp
Algori...
分类:
其他好文 时间:
2014-07-26 17:22:32
阅读次数:
413
题意:Flatopia岛要修路,这个岛上有n个城市,要求修完路后,各城市之间可以相互到达,且修的总路程最短.求所修路中的最长的路段最小生成树的一道题,很裸的一道题,不知道为什么就是编译过不了。#include#include#include#includeusing namespace std;in...
分类:
其他好文 时间:
2014-07-26 16:55:41
阅读次数:
270
# include
# include
# include
# include
# define N 100005
using namespace std;
vectorg[N];
int node[N];
int slove(int x)
{
int sum=0,i;
for(i=0;i<g[x].size();i++)
{
sum+=node[g[x][i]];
}
re...
分类:
其他好文 时间:
2014-07-26 15:21:40
阅读次数:
224
首先我们以50分为一单位,于是赢一次得1分输一次扣2分,由于每次都用小号打,所以容易观察出最后达到20分时应该分别为20分和19分。我们设dp[i]为i到i+1分的期望步数。则dp[i]=p*1+(1-p)*(dp[i-2]+dp[i-1]+dp[i]+1),前者是赢的期望,后者由于输了2分,所以变成i+1分时需要从i-2->i-1->i->i+1,就是dp[i-2]+dp[i-1]+dp[i]+...
分类:
其他好文 时间:
2014-07-26 15:02:20
阅读次数:
161