POJ 2356 Find a multiple / 3370 Halloween treats 鴿巢原理

題意:給定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;

HDU 1695 GCD 容斥原理+歐拉

題意:給你五個數a,b,c,d,k,令x ∈[a,b], y∈ [c,d]。求出有多少對(x,y)可以使gcd(x,y) == k。題中所有的a,b都等於1.題解:1. b /= k, d /= k, 這樣就轉換成求b,d之間有多少對互素。2.不妨令b<=d, 那麼我們枚舉y,當1<=y <=b的時候,與y互素的的個數就是phi(y)。3.當b < y <= d的時候,先將y因式分解 y =

POJ 1150 The Last Non-zero Digit 階乘最後非0位

轉自:http://www.cppblog.com/abilitytao/archive/2009/10/31/99907.html這個題怎麼來做呢?先別急,我們先來討論一下下面幾個子問題:1.如何求出n階乘中質因數x(比如說5)出現的次數?比如說15的階乘

HDU 2461 Rectangles 容斥原理

題意:座標繫上有N個矩形,給出了他們的左下頂點和右上頂點。每次操作是對其中的R個矩形進行染色,然後要你輸出這些被染色的矩形的面積之和(重疊部分不能重複計算)。題解:標準的容斥原理。#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>using namespace std;struct Rectangle { int x1, y1, x2,

POJ 1604 Just the Facts 階乘最後非0位

#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;

POJ 3244 Difference between Triplets 公式轉換

題意:兩個三元組(x1,y1,z1),(x2,y2,z2)的距離如下定義D = max {x1 − x2, y1 − y2, z1 − z2} − min {x1 − x2, y1 − y2, z1 − z2}現在給你n個三元組,讓你求出任意兩個三元組的距離之和。 題解:公式轉換非常有用,必須引起重視先簡化一下模型:令a = x1-x2, b=y1-y2, c=z1-z2則D = max {a,b,c} − min {a,b,c}這樣的話 D =

POJ 1006 Biorhythms 中國剩餘定理/擴充歐幾裡得

先看視頻: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 +

POJ 1061 青蛙的約會 擴充歐幾裡得

青蛙的約會Time Limit: 1000MS Memory Limit: 10000KTotal

POJ 3428 Formatting function (檔案輸入)

題意:給出輸入格式,判斷它的參數是否相匹配。* %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

POJ 3641 Pseudoprime numbers 偽素數測試

題意:判斷一個數是否是基於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;

POJ 2142 The Balance 擴充歐幾裡得,求|x|+|y|最小

題解:先做出兩個函數的映像,然後求|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 ){

POJ 2176 Folding (字串)

題意:個你一個字串將其進行壓縮,使得壓縮後的串長度最短。壓縮規則: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,

POJ 3185 高斯消元+DFS枚舉自由變數

題意:奶牛有20隻碗擺成一排,用鼻子頂某隻碗的話,包括左右兩隻在內的一共三隻碗會反向,現在給出碗的初始狀態,問至少要用鼻子頂多少次才能使所有碗都朝上。#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>using namespace std;int a[30][30], x[30];int fre[30], index[30], fnum;int equ, var,

POJ 2635 Pick-up sticks (線段相交)

題意:有些人沒事兒喜歡往地上任棍子,後面扔的可能蓋住前面扔的,顯然最後扔的那根棍子一定沒被壓住,求所有沒有被其它棍子壓住的棍子。題解:規範相交。用鏈表最佳化下。當然也可以用佇列儲存體下標。#include<cmath>#include<iostream>using namespace std;#define eps 1e-8#define max(x,y) ((x)>(y)?(x):(y))#define min(x,y)

POJ 2891 模線性方程組(mi mj 不互素)

題解: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) |

POJ 1850 Code 統計問題

題意:存在下面的編碼方式: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 )

POJ 1365 Prime Land 整數分解

題解:在求素數的過程中記錄下每個數的最小因素,a[n]表示n的最小因素,例如a[2]=2, a[12] = 3, a[16] = 2······#include<cstdio>#include<cstring>#include<memory>#include<cmath>using namespace std;const int MAX = 33333;int a[MAX], p[MAX];int r, pn;struct Result {

HDU 2222 Keywords Search (AC自動機入門題)

題意:題解://先調用PreProcess()初始化//Insert()添加串 Find()尋找串//get(char s) 返回字元s所對應的編號(考慮字元集合可能是’A’-’Z’或者”ACGT”等)//全部Insert後調用 bfs()求fail指標#include<cstdio>#include<queue>#include<cstring>#include<iostream>using namespace std;#define CN 2

POJ 3518 Prime Gap 素數

#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;

POJ 1095 Prime Cuts 素數

題解:#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[

總頁數: 61357 1 .... 13170 13171 13172 13173 13174 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.