Time of Update: 2018-12-06
package com.wangzhu.main;public class Main {/** * @param args */public static void main(String[] args) {work(new int[] { 1, 1, 1, 1, 1 });work(new int[] { 5, 4, 3, 2, 1 });work(new int[] { 1, 2, 3, 4, 5 });work(new int[] { 1, 7, 2, 3, 3, 4, 5, 5, 7,
Time of Update: 2018-12-06
使用過程中的一積累,備查。EasyUI 驗證框使用方法://***************************missingMessage:未填寫時顯示的資訊validType:驗證類型見下樣本invalidMessage:無效的資料類型時顯示的資訊required="true" 必填項class="easyui-validatebox" 文本驗證class="easyui-numberbox" 數字驗證*****************************//0、調用資料驗證方法
Time of Update: 2018-12-06
import java.io.BufferedInputStream;import java.util.Iterator;import java.util.Scanner;import java.util.Set;import java.util.TreeSet;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(new
Time of Update: 2018-12-06
很典型的動態規劃題很好的演算法:f(m, n) = f(m-n, n) + f(m, n-1)f(m, n): 把m個蘋果放到n個盤子中的方法數f(m, n-1): 把m個蘋果放到n-1個盤子中的方法數(其中至少有一個空盤子)f(m-n, n): 把m個蘋果放到n個盤子中,而且每個盤子中都有蘋果(先拿n個出來,等m-n個放好了,然後每個盤子放一個) /* * hrbeuapple.c * * Created on: 2011-10-10 * Author: bjfuwangzhu*/
Time of Update: 2018-12-06
/* * hdu1521.c * * Created on: 2011-8-31 * Author: 王竹*/#include<stdio.h>#include<string.h>#define nmax 15int num[nmax];double res[nmax], fac[nmax], temp[nmax];void init(int n) {int i; fac[0] = 1;for (i = 1; i <= n; i++) {
Time of Update: 2018-12-06
利用擴充歐幾裡德演算法可以解方程ax+by=c.當使用擴充歐幾裡德演算法時,當x+b時,y-a。歐幾裡德演算法 定理:gcd(a,b) = gcd(b,a mod b) 證明:a可以表示成a = kb + r,則r = a mod b 假設d是a,b的一個公約數,則有 d|a, d|b,而r = a - kb,因此d|r 因此d是(b,a mod b)的公約數 假設d 是(b,a mod b)的公約數,則 d | b , d |r
Time of Update: 2018-12-06
/* * hdu3923.c * * Created on: 2011-9-20 * Author: bjfuwangzhu*/#include<stdio.h>#include<math.h>#define LL long long#define nnum 1000000007LL x, y;LL modular_exp(int a, int b) { LL res, temp; res = 1 % nnum,temp = a %
Time of Update: 2018-12-06
由題知:(1+x/1!+x^2/2!+``+x^n/n!)^2*(1+x^2/2!+```)^2由e^x=1+x/1!+x^2/2!+```知原式=e^(2*x)*((e^x+e^(-x))/2)^2 =(1/4)*(e^(2*x)+1)^2 =(1/4)*(e^(4*x)+2*e^(2*x)+1) =(1/4)*(sia(4^n)*(x^n/n!)+2*sia(2^n)*(x^n/n!)+1) 由以上式子可知: x^n/n!的係數為(4^n+2*2^n+1)/4=4^(n-1)+2^
Time of Update: 2018-12-06
使用n%2==1判斷是否是奇數:import java.io.BufferedInputStream;import java.util.Scanner;public class Main { /** * @param args */ public static void main(String[] args) { int a; Scanner cin = new Scanner(new BufferedInputStream(System.
Time of Update: 2018-12-06
1)根據一下公式,直接計算 C(n,m) mod p = n*``*(n-m+1)/(1*``*m) mod p 計算分別分子nn、分母mm中p的個數和對p的餘數,若分子中p的個數多餘分母中p的個數,則結果為0, 若不是,則原式變為nn/mm mod p (nn,p)=1,(mm,p)=1 此時如何求逆元變得至關重要,以下有兩種解法。2) Lucas 定理:是用來求 C(n,m) mod p的值,p是素數。 描述為: Lucas(n,m,p)=C(n%p,m%p)*
Time of Update: 2018-12-06
/* 先說一個定理: 若正整數n可分解為p1^a1*p1^a2*...*pk^ak 其中pi為兩兩不同的素數,ai為對應指數 n的約數個數為(1+a1)*(1+a2)*....*(1+ak) 如180=2*2*3*3*5=2^2*3^2*5 180的約數個數為(1+2)*(1+2)*(1+1)=18個。 若求A/B的約數個數,A可分解為p1^a1*p2^a2*...*pk^ak, B可分解為q1^b1*q1^b2*...*qk^bk,則A/B的約數個數 為(a1-b1+1)*(a2-b2+1)
Time of Update: 2018-12-06
做法:直接求過不了只能考慮 對於gcd(M,N)=i 有Ci個M滿足此式 答案便是∑(Ci*i)gcd(M,N)=i <=> gcd(M/i,N/i)=1 而求gcd(M/i,N/i)=1 有多少個M/i滿足 這便是歐拉函數Phi()的定義所以就轉化為了求Phi(N/i)枚舉每個 M|N 求出Phi(N/i) 答案便是 ∑(Phi(N/i)*i)那麼如何枚舉每個 M|N 呢?很簡單 枚舉1到sqrt(N)的所有整數,所有的約數便是 j|N
Time of Update: 2018-12-06
題目連結:http://acm.hrbeu.edu.cn/index.php?act=problem&id=1010&cid=25其中P為非素數,所以有:將C(n,m)%p=p0^C0```pi^Ci%p#include<stdio.h>#include<string.h>#define LL long long#define nmax 100001int flag[nmax], prime[nmax];int plen;void mkprime()
Time of Update: 2018-12-06
#include<stdio.h>#include<string.h>#include<math.h>#define nmax 1000001int prime[nmax], plen;void init() {memset(prime, -1, sizeof(prime));int i, j;for (i = 2; i < nmax; i++) {if (prime[i]) {for (j = i + i; j < nmax; j += i) {
Time of Update: 2018-12-06
#include<stdio.h>#include<string.h>#include<math.h>#define LL long long#define nmax 3000001int prime[nmax], phi[nmax];int plen;void init() {int i, j; memset(phi, 0, sizeof(phi));for (i = 2, plen = 0; i < nmax; i++) {if (
Time of Update: 2018-12-06
對於本題的因數m,只需要將其化為素因子的乘積形式,其中每一個素因子的個數為mi,之後只需要求得每一個素因子pi在組合數中的個數Ci,然後將取Ci/mi中的最小的那個,就是該因數在組合數中的個數。代碼如下:/* * fafu1079.c * * Created on: 2011-10-9 * Author: bjfuwangzhu*/#include<stdio.h>#include<string.h>#include<math.h>#define
Time of Update: 2018-12-06
/** * 和為n的連續正數列 * 定義序列start=1,end=2,當和sum大於n時,則先將和sum減去最小的start,並移動start++,若是小於n,則sum+=end * ,end++,若是等於則輸出[start,end],並使sum加上end,++end * * @param n */public static void sequenceN(int n) {int start = 1, end = 2, mid = (n + 1) / 2, sum = start +
Time of Update: 2018-12-06
1.是否存在兩個數的和與已知數(key)相等。A:窮舉:在數組中任選兩個數,判斷是否等於已知數,複雜度O(N^2).B:二分:先排序(若是有序,則不需要),然後二分尋找M-array[i]是否存在於這個數組,複雜度O(N*log(N)).C:先排序(若是有序,則不需要),然後用兩個指標(頭指標head與尾指標tail),當*head+*tail>key,則tail--,若是小於,則是head++,若是相等,則是存在。對於C:int getResult(int *num, int
Time of Update: 2018-12-06
/* * poj1808.c * Created on: 2011-10-12 * Author: bjfuwangzhu *//* *> 考慮形如x2≡n(mod m)的同餘式,其中m > 1,(m,n)=1。 *> 若此同餘式有解,則n稱為模m的二次剩餘;若此同餘式無解,則n稱為模m的二次非剩餘。 *> 設p是一個奇素數,則模p的二次剩餘和二次非剩餘個數正好是“一半對一半”, *> 下表給出幾個較小的素數模的二次剩餘和非剩餘: *> > p
Time of Update: 2018-12-06
由於素數P比較小,所以可以先打表,求出小於P的數的階乘對與該素數的餘數,這樣節省了中間求階乘的時間。/* * soj3290.c * * Created on: 2011-10-10 * Author: bjfuwangzhu*/#include<stdio.h>#define LL long long#define nmod 10009int num[nmod];void init() {int i;for (i = 1, num[0] = 1; i <