- 博客(12)
- 收藏
- 关注
原创 欧几里得算法(辗转相除)
#include using namespace std;int gcd(int x,int y)//最大公约数{ return y==0?x:gcd(y,x%y);}int lcm(int x,int y)//最小公倍数{ return x/gcd(x,y)*y;}int main(){ int x,y; while(c
2017-04-30 10:56:56 1241
原创 Eratosthenes(埃拉托色尼)筛法
对于每个不超过n的非负整数p,删除2p,3p,4p,处理完所有的数之后,没被删除的就是素数。#include #include using namespace std;int main(){ int n; cin >> n; int * a = new int[n]; for (int i = 0; i a[i] = i;
2017-04-30 10:46:22 506
原创 数学函数
三角函数:(所有参数必须为弧度)1.acos函数申明:acos (double x);用途:用来返回给定的 X 的反余弦函数。2.asin函数申明:asin (double x);用途:用来返回给定的 X 的反正弦函数。3.atan函数申明:atan (double x);用途:用来返回给定
2017-04-29 22:27:54 310
原创 错误的算法
有道题目是这样的:输入一个 n行 m列网格,找一个格子,使得它所在的行和列中所有格子的数之和最大。如果答 案不唯一,输出任意解即可。比如,在下面的例子中,最优解是(1,3),即第一行和的三列的交 点(行从上到下编号为1~n,列从左到右编号为1~m),所有7 个数之和为35。快要比赛的时候,有一个裁判想到了这样一
2017-04-26 09:34:00 986
原创 阶乘除法
输入两个正整数 n, m,输出n!/m!,其中阶乘定义为n!= 1*2*3*...*n (n>=1)。 比如,若n=6, m=3,则n!/m!=6!/3!=720/6=120。是不是很简单?现在让我们把问题反过来:输入k=n!/m!,找到这样的整数二元组(n,m) (n>m>=1)。如果答案不唯一,n应该尽量小。比如,若 k=120,输出应该是n=5,
2017-04-26 09:12:00 2257
转载 背包理论解析
背包之01背包、完全背包、多重背包详解 PS:大家觉得写得还过得去,就帮我把博客顶一下,谢谢。首先说下动态规划,动态规划这东西就和递归一样,只能找局部关系,若想全部列出来,是很难的,比如汉诺塔。你可以说先把除最后一层的其他所有层都移动到2,再把最后一层移动到3,最后再把其余的从2移动到3,这是一个直观的关系,但是想列举出来是很难的,也许当层数n=3时还可以模拟下,再大一些就
2017-04-25 15:57:32 2299
原创 POJ---2236 Wireless Network【并查集】
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the
2017-04-25 11:14:32 246
原创 HDU---1829 A Bug's Life【并查集】
BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite ge
2017-04-24 21:38:41 290
原创 POJ---1703 Find them, Catch them【并查集】
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which
2017-04-24 20:41:32 230
原创 POJ---2524 Ubiquitous Religions【并查集】
There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university be
2017-04-17 15:40:47 273
原创 POJ---1611 The Suspects【并查集】
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to
2017-04-17 13:26:54 288
原创 HDU---1114 Piggy-Bank【完全背包】
Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes
2017-04-16 14:57:02 288
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人