
组合数学专项
人面桃花相映红
BNU student
展开
-
hdu2710 找出一列数中含最大素数的那个数
Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the原创 2016-10-10 09:35:01 · 812 阅读 · 0 评论 -
欧几里得扩展
拓展欧几里得:当 gcd ( a , b )= d 时,求绝对值和最小的 x , y 使得 x * a + y * b = d ;d = gcd ( a , b ) = gcd ( b , a mod b );设:x1 * a + y1 * b = d ; ①x2 * b + y2 * ( a mod b ) = d ; ②因为 a mod b = a -原创 2017-09-06 20:52:35 · 260 阅读 · 0 评论 -
poj 2566
#include #include #include #include #define LL long longusing namespace std;vector > ans;void solve(LL n){ ans.clear(); LL s = 1, t = 1; LL sum = 0; while (s * s <= n) {原创 2017-04-27 15:32:28 · 704 阅读 · 1 评论 -
hdu 1018 Big NUmber
#include#includeusing namespace std;int main(){ int n,test,i,ans; double t; cin>>test; while(test--) { cin>>n; t=0; for(i=2;i<=n;i++) t+=log原创 2017-05-04 15:04:57 · 285 阅读 · 0 评论 -
lightpj 1248
题目大意:给出一个n面的色子,问看到每个面的投掷次数期望是多少? #include #include #include #include #include #include using namespace std; int main(){ double ans;原创 2017-05-03 20:22:42 · 184 阅读 · 0 评论 -
lightoj 1030 Discovering Gold 概率期望
题意:有一个直线的金矿,每个点有一定数量的金子;你从0开始,每次扔个骰子,扔出几点就走几步,然后把那个点的金子拿走;如果扔出的骰子超出了金矿,就重新扔,知道你站在最后一个点;问拿走金子的期望值是多少;思想:p[i]的期望是p[i] = p[i+1]/6+p[i+2]/6+p[i+3]/6+p[i+4]/6+p[i+5]/6;先求出最后一个期望,然后倒着向前求,每一个的期望就等于当前的期望加上可以到原创 2017-05-03 16:29:22 · 261 阅读 · 0 评论 -
lightoj 1104 Birthday Paradox 概率期望
题意:一年有N天,问至少有多少个人才能保证至少其中两个人的生日在同一天的概率大于等于0.5。思路:用相反事件,就是求所有人不在同一天生日的概率小于0.5;// created by renmiantaohua// date:2017/5/3#include#include#include#include#includeusing namespace std;int原创 2017-05-03 15:33:57 · 278 阅读 · 1 评论 -
zoj 3870 异或运算
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 1e5+5;int n,a[N],num[N];void Cal(int t){ int l = 31; while(l >= 0) { if原创 2017-04-12 21:12:59 · 237 阅读 · 0 评论 -
埃氏筛法
#include<iostream>#include<stdio.h>using namespace std;int const maxn = 1000010;int isprim[1000010];int prim[1000010];int num= 0;int n;int judge(int n){ for(int i = 0; i < n; i++)原创 2017-03-16 15:52:16 · 308 阅读 · 0 评论 -
nyoj 19 擅长排列的小明
http://acm.nyist.net/JudgeOnline/problem.php?pid=19 数字的排列问题 字典序全部输出。 1.substr函数的作用是截取字符substr(a[2],a+n)截取从数组中第二个开始的向后n个的一段。如果是string s1定义的 可以使用substr(s1.begin(),s1.end()); 2.next_permutation(s1.beg原创 2016-11-20 10:32:30 · 308 阅读 · 0 评论 -
快速幂
快速幂公式: typedef long long LL;//视情况定类型 LL fun(LL x, LL n) { LL res = 1; while (n > 0) { if (n & 1)//&按位与判奇偶 4>>1 = 4/2 2<<1 = 2*2 res = (转载 2016-09-19 21:40:45 · 187 阅读 · 0 评论 -
hdu 1999 可摸数问题
对一个数的所有因数求和的打表方法 for(int i =1; i < maxn; i++) { for(int j =i*2 ; j< maxn ; j=j+i) { sum[j]+=i; } }#include <iostream>#include <stdi原创 2016-10-11 17:30:04 · 249 阅读 · 0 评论 -
欧几里得算法 求最大公约数
int gcd(int da,int xiao) //da为两个数中较大的数 小则为较小的{ int temp; while (xiao!=0) { temp=da%xiao; da=xiao; xiao=temp; } return(da); }原创 2016-07-29 16:01:11 · 380 阅读 · 0 评论 -
poj 1006
poj 1006 题的思路不是很难的,可以转化数学式:现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设!那么就可以得到三个式子:( num + d ) % 23 == p; ( num + d ) % 28 == e; ( num + d ) % 33 == i;p,e,i,d 是我们输入的,那么我们需要求出num即可,为了方便,我们将num+d暂时作为一个整体!令转载 2016-09-21 10:46:43 · 337 阅读 · 0 评论 -
367. 有效的完全平方数
给定一个正整数num,编写一个函数,如果num是一个完全平方数,则返回 True,否则返回 False。说明:不要使用任何内置的库函数,如sqrt。思路:一个数的完全平方数必然等于前m个奇数的和: n^2=1+3+5+......(2*m-1);class Solution {public: bool isPerfectSquare(int num) { ...原创 2019-04-16 10:39:11 · 117 阅读 · 0 评论