題意:給定n個正整數,從中任意的選出一些數,使他們的和能夠被n整除。題解:《組合數學》P17#include<cstdio>#include<cstring>using namespace std;const int MAXN = 20000;int sum[MAXN], num[MAXN], flag[MAXN];void print ( int s, int t ){ printf("%d\n", t - s + 1); for ( int i = s;
#include<cstdio>int get2 ( int n ){ if ( n == 0 ) return 0; return n/2 + get2(n/2);}int get5 ( int n ){ if ( n == 0 ) return 0; return n/5 + get5(n/5);}int g ( int n, int x ){ if ( n == 0 ) return 0;
先看視頻:http://v.youku.com/v_show/id_XMTExNTAzOTIw.html #include<cstdio>int main(){ int p, e, i, d; int num, cnt = 1; while ( scanf("%d%d%d%d",&p,&e,&i,&d) ) { if ( d == -1 ) break; num = (5544*p +
題意:給出輸入格式,判斷它的參數是否相匹配。* %s — argument as a string* %d — argument as an integer value, without any leading zeroes* %% — literal '%' characterFormatting error is generated if:* number of arguments required by format specifiers is not equal to the
題意:判斷一個數是否是基於a的偽素數。只有當p是合數且a^p = a ( mod p ) 時,才輸出yes。題解:Miller_Rabin素數測試。#include<cstdio>#include<ctime>#include<cstdlib>using namespace std;#define lint __int64lint modular_exponent ( lint a, lint b, lint n ){ lint ret = 1;
題解:先做出兩個函數的映像,然後求|x|+|y|的最小值。|x|+|y|=|x0+b/d *t |+|y0-a/d *t| 這個關於t的函數的最小值應該在t零點附近(在斜率大的那條折線的零點附近,可以觀察出來)。以下三種情況中,函數最小值都應該出現在B點附近。#include<cstdio>#include<algorithm>using std::swap;int Egcd ( int a, int b, int &x, int &y ){
題意:個你一個字串將其進行壓縮,使得壓縮後的串長度最短。壓縮規則:A sequence that contains a single character from 'A' to 'Z' is considered to be a folded sequence. Unfolding of this sequence produces the same sequence of a single character itself. If S and Q are folded sequences,
題解:x = ai ( mod mi ) 1 <= i <= k先考慮k==2的情況:x = a1 ( mod m1 )x = a2 ( mod m2 )方程組有解的充分必要條件是: d | (a1-a2) ,其中 d = (m1,m2)證明如下:必要性: 設 x 是上面同餘方程組的解,從而存在整數q1,q2使得x=a1+m1*q1,x=a2+m2*q2,消去x即得a1-a2 = m2q2-m1q1。由於d=(m1,m2),故d | (a1-a2)。充分性:若d=(m1,m2) |
題意:存在下面的編碼方式:a - 1 b - 2 ... z - 26 ab - 27 ... az - 51 bc - 52 ... vwxyz - 83681 其中字串的長度逐漸增加,並且每一個字串的字元只能是升序。例如b不能排在a的前面。#include<cstdio>#include<cstring>using namespace std;#define lint __int64lint C ( int m, int n ){ if ( m < n )
#include<cstdio>#include<cstring>using namespace std;const int MAX = 1299710;int p[MAX], a[MAX], pn;;void prime (){ int i, j; pn = 0; memset(a,0,sizeof(a)); for ( i = 2; i < MAX; i++ ) { if ( ! a[i] ) p[pn++] = i;
題解:#include<cstdio>#include<cstring>using namespace std;const int MAX = 2000;int p[MAX], a[MAX], pn;;void prime (){ int i, j; memset(a,0,sizeof(a)); p[1] = 1; pn = 1; for ( i = 2; i < MAX; i++ ) { if ( ! a[i] ) p[