POJ 1006 生理周期(中國剩餘定理/類比)

 中國剩餘定理用來解決以下問題:對於N個兩兩互質的整數,求最小公解X,X滿足X mod N1 = A1, X mod N2 = A2……X mod Nn = An 我國有一本數學古書「孫子算經」有這樣一道問題:「今有物,不知其數,三三數之,剩二;五五數之,剩三;七七數之,剩二。問物幾何?」意思是一個整數除以三餘二,除以五餘三,除以七餘二,求這個整數(滿足條件且最小) 做法是:

Sicily 1799 Slides(離散化處理)

//離散化處理#include<iostream>#include<vector>#include<cstring>#include<algorithm>using namespace std;struct coordinate//座標結構體{int x,y;int id;//為每個點標記一個ID,方便關聯,id和id+1的便屬於同一個矩形int color;bool used;};vector<coordinate> v;bool

POJ 2033 Alphacode

DescriptionAlice and Bob need to send secret messages to each other and are discussing ways to encode their messages: Alice: "Let's just use a very simple code: We'll assign 'A' the code word 1, 'B' will be 2, and so on down to 'Z' being assigned 26.

Sicily 1146 採藥(DP動態規劃——01背包問題)

//傳統非滾動數組實現形式#include<iostream>#include<cmath>using namespace std;int s[1000][1000];int main(){int T,M,t,v,_max = -1;//T為時間上限(背包容量),M為藥草份數(物品總數)scanf("%d%d",&T,&M);for(int i = 1;i <= M;++i){scanf("%d%d",&t,&v);for(int

Sicily 1154 Easy Sort(排序)

//簡單快速排序,原來在Sicily上用qsort要添加algorithm的,難怪校賽的時候用next_permutation出錯,原來是沒添加<algorithm>真是可惡!經驗不夠啊!!//POJ跟Sicily 差別這麼大……#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int arr[1000001];int cmp_int(const

POJ 2524 Ubiquitous Religions(並查集)

//並查集的簡單應用——帶路徑壓縮的並查集//平攤分析後,每個點只需遍曆一次即可建立相應並查集,搜尋的複雜度是O(1);//計算不相交集合的個數#include<iostream>using namespace std;int fa[50010],n,m,ans,vis[50010];void initSet()//初始化{for(int i = 1;i <= n;++i)fa[i] = i;}int Find(int x){int temp_x = x;if(x == fa[

POJ 1611 The Suspects(並查集)

//並查集,統計不相交集合的元素個數#include<iostream>using namespace std;int n,m,k,fa[30010],num[30010],x,y;void initSet(){for(int i = 0;i < n;++i)fa[i] = i;}int Find(int x){if(x == fa[x])return x;else return fa[x] = Find(fa[x]);//路徑壓縮}void Union(int x,int

POJ 1308 Is It A Tree(類比題)

//最簡便的做法,根據樹的定義來做//樹有N個頂點,N-1條邊//個人覺得這道題比較撲街,資料範圍也沒給,細節那麼多,連空樹、多重邊這種東西都要考慮#include<iostream>using namespace std;int node[1000],edge[1000][1000];//記錄出現過的點和邊bool ok;int x,y,N,E,n;void init(){N = E = n = 0;ok =

POJ 1149 PIGS(網路流—最大流)

http://imlazy.ycool.com/post.2059102.html看了這篇文章才做出來的,收穫很大,膜拜神牛!網路流的痛點在於圖的構建以及圖的簡化//網路流——最大流//此題的關鍵是構圖和對圖的簡化以及流量的合并//可參見http://imlazy.ycool.com/post.2059102.html//有非常詳細的講解#include<iostream>#include<queue>#include<cstring>#define INF

POJ 1087 A Plug for UNIX(網路流—最大流(最大二分匹配))

//網路流——通過構圖用最大流來作做大匹配//將用電器(device)與源點相連//插座(plug)和匯點相連//適配器與插座相連,且權值為INF//將最大匹配問題構圖轉化為最大流問題,再用匯點總流減去最大流得到答案#include<iostream>#include<queue>#include<map>#include<cstring>#include<string>#define INF 2000000000using

Sicily 1201 01000001(高精度運算)

//二進位高精度運算#include<iostream>#include<cstring>#include<algorithm>struct BinaryNum//高精度結構體{char num[100];int data[100];int len;void reverse()//逆序轉換{for(int i = 0;i < len;++i){data[i] = num[len - i - 1] - '0';}}void print()

Sicily 1252 Defining Moment(字串遞迴)

//類比題,遞迴處理即可,利用string 類強大的可+性,可簡單實現遞迴函式//一開始調用了STL的string類的substr函數,結果restric function了//真是無語。。。#include<iostream>#include<string>using namespace std;string Substr(string word,int position,int len){string substr;for(int i = position;i -

Sicily 1090 Highways(Kruskal最小產生樹)

//求最小產生樹中的最大邊//第一次寫Kruskal演算法,感謝JSH同學的指點//並查集的優越性,平攤後只需要O(1)的時間即可擷取結果//求最小產生樹時時刻注意邊數和結點數是不同的,不要混淆,因為弄混了WA了3次#include<iostream>#include<cstdlib>#include<algorithm>using namespace std;int G[505][505];int n,t,_max;struct

POJ 1661 Help Jimmy(動態規劃)

//動態規劃//將板按高度排序//記錄到達每塊板的左右端點所需的最少時間,和每塊板從左右兩邊跳下去的下一塊板指標//從高到低不斷迭代更新最少時間所需值//注意邊緣處理和直接落地的情況以及滿足最大跳樓高度這些條件#include<iostream>#include<algorithm>#define INF 1000000000;using namespace std;struct Plat{int x,y,h;int R_next;//從右端點掉下去的下一塊板int L_

POJ 1258 Agri-Net(最小產生樹)

//Kruskal + 並查集#include<iostream>#include<algorithm>using namespace std;int fa[101];//父親指標數組int G[105][105];//圖int n,e;//點數和邊數struct edge//存放邊的結構體{int u;int v;int w;}E[5000];bool cmp(edge a,edge b)//對邊權進行排序的排序比較函數{return a.w <

POJ 2719 Faulty Odomete(公式遞推)

//公式遞推//列表找規律,比如讀取各位為8,那麼知道有1個被跳過,讀取十位為3, 那麼算從1到30共有多少位被跳過了,讀取百位為5,計算從1到500共有多少位被跳過了//然後分類討論,讀取的這個位元>=5時是1種情況,<5是另一種情況#include<iostream>#include<cmath>using namespace std;int calculate(int n){int ans = 0;int carry = 1;int bit =

POJ 3041 Asteroids(最大二分匹配)

//二分圖最大匹配(匈牙利演算法)//行列匹配,按照題目意思是求最小點覆蓋//根據圖論知識,最大匹配數等於最小點覆蓋,因此將問題直接轉化為二分圖最大匹配來處理#include<iostream>#include<cstring>using namespace std;const int MAXN = 505;bool g[MAXN][MAXN];bool check[MAXN];//檢查數組int uMatch[MAXN],vMatch[MAXN],U,V;bool

POJ 3020 Antenna Placement(最大二分匹配)

//最大二分匹配(匈牙利演算法)//這題實際上是求最小路徑覆蓋,但根據最小路徑覆蓋的定義可以將它轉化為最大二分匹配//最小路徑覆蓋 = |V| - 最大獨立集 = |V| - 最大二分匹配 (二分圖中最大獨立集 = 最大二分匹配)//但是在構圖過程中,匹配是雙向的,即<u,v> 和<v,u>都算匹配,因此匹配數多了1倍,所以要除以2//最後得出公式: ans = V + maxMatch/2#include<iostream>using

喬布斯在斯坦福大學演講原文

Stanford Report, June 14, 2005‘You’ve got to find what you love,’ Jobs saysThis is the text of the Commencement address by Steve Jobs, CEO of Apple Computer and of Pixar Animation Studios, delivered on June 12, 2005.I am honored to be with you today

Sicily 1308 Dependencies among Jobs(圖的搜尋)

//圖的搜尋遍曆//“We assume that there is only one job processing in one

總頁數: 61357 1 .... 13014 13015 13016 13017 13018 .... 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.