原创 POJ 3723 Conscription【招募士兵】
原題鏈接 思路:把男生女生都當作頂點,把把親密度的負數當作權值,就是最小生成樹問題。 AC代碼: #include <iostream> #include <cstdio> #include <algorithm> #inclu
原创 ***POJ 2718 Smallest Difference【next_permination】
原題鏈接 題意:數字排序組成兩個數,求最小差值。 思路: next_permutation函數的應用,歷遍把數組所有的可能排列順序。 爲求最小差值,分割數組時應使兩個數的位數差儘可能小(爲1),選取中間值mid爲第二個數的開頭
原创 ***POJ 3617 Best Cow Line【牛排隊】
原題鏈接 貪心法,字典序最小問題 AC代碼: #include <iostream> #include <algorithm> using namespace std; char cow[2001]={0}; int n; in
原创 ***POJ 1182 食物鏈
原題鏈接 Description 動物王國中有三類動物A,B,C,這三類動物的食物鏈構成了有趣的環形。A喫B, B喫C,C喫A。 現有N個動物,以1-N編號。每個動物都是A,B,C中的一種,但是我們並不知道它到底是哪一種。
原创 POJ 5253 Fence Repair
原題鏈接 思路:倒着想,木塊已經全部切割,每次選擇最小的兩塊合併,直到合併爲一塊爲止。 AC代碼: #include <iostream> #include <algorithm> #include <stdlib.h> usin
原创 POJ 3187 Backward Digit Sums
原題鏈接 思路:N最大爲10,可以用next_permulation。 AC代碼: #include <stdio.h> #include <algorithm> using namespace std; //由於next_pe
原创 POJ 1979 Red and Black
原題鏈接 思路:經典深搜 AC代碼: #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring
原创 POJ 3050 Hopscotch
原文鏈接 思路:dfs,以每個格子爲起點,上下左右搜索,6次截至(step=5,從0開始),到達過的數字用vis記錄,避免重複。 AC代碼: #include <iostream> #include <cstdio> #incl
原创 POJ 3255 Roadblocks
原題鏈接 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends
原创 ***POJ 3669 Meteor Shower【流星雨】
原文鏈接 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will
原创 POJ 1742 Coins
原題鏈接 Description People in Silverland use coins.They have coins of value A1,A2,A3…An Silverland dollar.One day Ton
原创 POJ 3176 Cow Bowling
原題鏈接 思路:動態規劃。 動態方程:dp[i][j] = dp[i][j] + max(dp[i-1][j-1], dp[i-1][j]) dp[i][j]表示到點(i,j)的最大數字和。 AC代碼: #include <i
原创 POJ 1064 Cable master
經典二分 AC代碼: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #includ
原创 POJ 3069 Saruman's Army
原題鏈接 Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep
原创 POJ 2376 Cleaning Shifts
原題鏈接 思路:貪心。 AC代碼: #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring>