
数学
文章平均质量分 65
akxxsb
写写博客装装逼,存代码
展开
-
hdu 2047
不废话,直接代码#define Max 55#include#include#includeint n;long long c[Max],k[Max],m[Max];//c,k,m分别为长度为n时方法数和非o的字符个数和字符o的个数void ans(){ k[1]=2;m[1]=1;c[1]=3; for(int i=2;i<=50;i++) {原创 2014-02-24 11:18:46 · 1057 阅读 · 0 评论 -
微软面试题之以递增顺序打印2^i*3^j*5^k
以递增顺序打印出2^i*3^j*5^k的前n项。假设当前已经求出第x项,那么第x+1项一定是由前x项中的某项乘2,或乘3,或乘5,得到的大于第x项中最小的那个数,于是我们立即得到一个n^2的算法,代码如下#include using namespace std;typedef long long LL;const int MAX = 1e4+10;LL a[MAX];int main原创 2015-01-21 21:38:07 · 1698 阅读 · 1 评论 -
CSU1563 组合数学
C - LexicographyTime Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %lluSubmit Status Practice CSU 1563DescriptionAn anagram of a string is any string that c原创 2015-04-20 01:09:06 · 1570 阅读 · 0 评论 -
ZOJ 3868(容斥原理+快速幂)
GCD ExpectationTime Limit: 4 Seconds Memory Limit: 262144 KBEdward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, x2,…,xm} (each nonempty subset has原创 2015-04-27 01:55:25 · 1214 阅读 · 0 评论 -
UVA 11181(数学概率)
有n个人去超市,第i个人买东西的概率为p[i],逛完之后又r个人买了东西,求每个人实际买东西的概率。条件概率公式的应用,具体分析见算法竞赛入门经典第二版p327#include #include #include #include using namespace std;const int maxn = 100 + 10;double p[maxn],a[maxn];原创 2015-05-08 20:58:46 · 951 阅读 · 0 评论 -
UVA 10622 Perfect P-th Powers(数论)
UVA - 10622Perfect P-th PowersTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionProblem E: Perfect Pth Powers原创 2015-05-07 01:31:08 · 894 阅读 · 0 评论 -
UVA 1645(dp)
输入n,统计有多少个n节点的有根树。使得每个深度中所有节点的子节点数相同。可以根据节点的孩子个数dp。开始写了个记忆化,dp[n][p]表示n个节点,第一个节点有p个孩子的方案数#includeusing namespace std;typedef long long ll;const int maxn = 1000 + 5;const ll mod = 1e9 + 7;原创 2015-05-07 15:40:25 · 631 阅读 · 0 评论 -
矩阵小结
1.矩阵快速幂,用倍增来加速(O(n^3*logk))2.矩阵求解递推关系第n项(n很大)可以构造矩阵,用矩阵快速幂迅速求出。3.给定起点和终点求从起点到终点恰好进过k步的方案数可以直接对可达矩阵相乘k次得到结果4.矩阵乘法的顺序对时间影响比较大(提高Cache命中率),kij最快而且还可以进行稀疏矩阵加速(当a[i][k]为0时没必要进行运算)。因为最近在搞矩阵,所以准备写一个矩原创 2015-05-28 01:45:03 · 1344 阅读 · 6 评论 -
hdu 5212(容斥原理)
CodeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 77 Accepted Submission(s): 27Problem DescriptionWLD likes playing with co原创 2015-04-27 01:43:54 · 1244 阅读 · 0 评论 -
UVA 1638(动态规划)
有高为1到n的杆子各一根排成一行,从左往右能看见l根,从右往左能看见r根,问可能的方案数。dp[i][j][k]表示i根高度不同的杆子从左往右能看见j根,从右往左能看见k根,根据高度最低的那根杆子分类。#include #include #include #include using namespace std;typedef long long ll;const in原创 2015-05-08 21:32:23 · 1067 阅读 · 0 评论 -
POJ 3904(容斥原理)
Sky CodeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1750 Accepted: 545DescriptionStancu likes space travels but he is a poor software developer and原创 2015-06-04 22:39:48 · 926 阅读 · 0 评论 -
Codeforces Round #305 (Div. 1) C(容斥原理)
C. Mike and Foamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike is a bartender at Rico's bar. At Rico原创 2015-06-04 22:45:15 · 919 阅读 · 0 评论 -
LA 3905(扫描线)
MeteorTime Limit: 3000msMemory Limit: 131072KBThis problem will be judged on UVALive. Original ID: 390564-bit integer IO format: %lld Java class name: MainPrev Submit Status S原创 2015-11-26 00:37:13 · 727 阅读 · 0 评论 -
Codeforces Round #240 (Div. 2) Mashmokh and Numbers
题意找出一组数列,满足每相邻的两个数的最大公因数和为给定的值。,注意相邻两个数的公约数为一就好做了,注意下边界即可C. Mashmokh and Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutp原创 2014-04-09 23:12:11 · 1362 阅读 · 0 评论 -
hdu 2048(递推错排)
#define Max 25#includedouble jie(int n){ double f=1; for(int i=2;i<=n;i++) f*=i; return f;}int n;double a[Max],k;int main(){ //freopen("input.txt","r",stdin); a[1]=0;原创 2014-02-24 13:05:34 · 1087 阅读 · 0 评论 -
hdu 2045(简单递推)
注意分类讨论,第n-1个格子和第一个格子同色时第n个格子有两种涂法,不同色就只有一种。#define Max 55#include#include#includeint n;long long c[Max];int main(){ //freopen("input.txt","r",stdin); c[1]=3;c[2]=6;c[3]=6; long lon原创 2014-02-23 23:45:14 · 851 阅读 · 0 评论 -
hdu 2046(递推)
n规模的格子只能从n-1和n-2得来,n-1的时候我们增加一个2×1格子,竖着放,可以有f(n-1)种放法,n-2时候我们可以增加2×2个格子,2个都横着放,可以有f(n-2)种方法。注意本题思想不错,如何从一种状态达到另一种状态,递归有时候还是很有用的。#define Max 55#include#include#includeint n;long long c[Max];i原创 2014-02-24 00:26:47 · 958 阅读 · 0 评论 -
hdu 2058(水)
#include#define MAX 1000010int N,M;int ans1[MAX],ans2[MAX];int main(){ //freopen("input.txt","r",stdin); while(scanf("%d%d",&N,&M)!=EOF) { if(!M&&!N)return 0; int t=-1; for(i原创 2014-03-05 22:48:43 · 883 阅读 · 0 评论 -
NEUOJ 1403: XL's Math Problem II
题目如图所示,由于n很大直接枚举肯定不行,所以以此枚举商x,把最左边的i和最右边的j使得满足n/i=x,n/j=x,的i,和j求出来,j-i+1就是商x的个数。#include#include#includeusing namespace std;typedef long long LL;int main(){ int n,cas,L,R,cnt=0; LL ans原创 2014-03-30 21:52:04 · 1160 阅读 · 0 评论 -
1408: The Game(博弈论)尼姆博弈
1408: The Game时间限制: 1 Sec 内存限制: 256 MB提交: 54 解决: 25[提交][状态][讨论版]题目描述John and his brother are playing a game. There are several piles of stones. At first John has to pick up some ston原创 2014-03-30 22:00:01 · 1171 阅读 · 0 评论 -
HDU 2095
好吧,这题我开始先排序超时了,后来用了异或,再次见识到位运算的强大。。。 我们知道A^A=0A^0=A所以只要把输入的数字全部异或 那么留下来的就是奇数个的数字。find your present (2)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/1024 K (Ja原创 2014-03-31 22:19:43 · 1128 阅读 · 0 评论 -
NEUOJ 1391: Big Big Power(费马小定理&快速幂)
费马小定理是数论中的一个重要定理,其内容为: 假如p是质数,且(a,p)=1,那么 a^(p-1) ≡1(mod p)。即:假如a是整数,p是质数,且a,p互质,那么a的(p-1)次方除以p的余数恒等于1。稍微变化一下就是(a^b)%p=a^[b%(p-1)]%p。本题计算a^(b^c)%(1e9+7)先把(b^c)看成整体应用费马小定理有,a^[(b^c)%(1e9+7-1)]=[a原创 2014-04-06 17:56:29 · 1975 阅读 · 0 评论 -
LIGHTOJ 1027
应该是概率的题,还有最大公约数约分的问题。E - LIGHTOJ 1027Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionYou are in a maze; seeing n doors in fr原创 2014-03-26 20:10:39 · 1223 阅读 · 0 评论 -
POJ 1862
H - StripiesTime Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64uSubmit StatusAppoint description: System Crawler (2013-05-30)DescriptionOur chemical原创 2014-04-20 20:00:56 · 819 阅读 · 0 评论 -
UVA 10025(数学)
The ? 1 ? 2 ? ... ? n = k problem The problemGiven the following formula, one can set operators '+' or '-' instead of each '?', in order to obtain a given k? 1 ? 2 ? ... ? n =原创 2014-05-08 23:57:30 · 1109 阅读 · 0 评论 -
筛法求素数变式
Quite Good NumbersTime Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KBTotal submit users: 73, Accepted users: 52Problem 12876 : No special judgementProblem descr转载 2014-08-09 20:38:19 · 653 阅读 · 0 评论 -
LA 2678 Subsequence(尺取法)
SubsequenceTime Limit: 3000msMemory Limit: 131072KBThis problem will be judged on UVALive. Original ID: 267864-bit integer IO format: %lld Java class name: MainPrev Submit Sta原创 2015-11-26 00:49:42 · 732 阅读 · 0 评论