- 博客(15)
- 资源 (2)
- 收藏
- 关注
原创 pku 3253 - Fence Repair
題目:有很多籬笆,每次把兩個籬笆合起來,代價使他們的長度,求所有籬笆合起來的最小代價。分析:貪心,哈弗曼樹。直接利用優先隊列求解哈弗曼樹即可。說明:數學和算法被鄙視了╮(╯▽╰)╭。#include #include #include #include #include using namespace std;int main(){ int n, leaf, sma
2016-06-24 10:00:32 534
原创 UVa 11687 - Digits
題目:計算一個序列,每個元素德語前一個串的長度,求第幾個序列和前面的相同。分析:簡單題。直接模擬運行即可。說明:注意數組開大一點繁殖溢出,╮(╯▽╰)╭。#include #include #include char buf[10001];int main(){ while (gets(buf)) { if (!strcmp(buf, "END")) { br
2016-06-21 12:01:12 863
原创 UVa 11679 - Sub-prime
題目:有一些銀行他們分別有一些儲蓄,然後各銀行間進行借貸,問是否所有的銀行儲蓄都可以支付借貸。分析:模擬。直接模擬計算即可。說明:╮(╯▽╰)╭。#include int reserves[22];int main(){ int b, n, from, to, value; while (~scanf("%d%d",&b,&n) && n+b) { for (int
2016-06-21 10:02:11 781
原创 pku 3069 - Saruman's Army
題目:在一條馬路上有很多個點,在某些點上安裝照明半徑是r的燈,求最小的燈覆蓋所有的點。分析:貪心。每次從左享有掃描找到最大的覆蓋範圍,確定下一個點即為最少。說明:測試樣例輸出有問題,第一個輸出的3,╮(╯▽╰)╭。#include #include #include #include using namespace std;int x[1001];int main()
2016-06-21 07:44:28 251
原创 pku 3617 - Best Cow Line
題目:已知串S和空串T,每次從S的兩端中去一個字符放入T的尾部,求T的最小字典序。分析:貪心。每次雙向掃描,取字典序小的字串方向的字符。說明:不能直接比較兩端字符,反例DCCEAAD。#include char S[2002];int main(){ int n; while (~scanf("%d",&n)) { getchar(); for (int i = 0
2016-06-20 07:43:44 275
原创 pku 2386 - Lake Counting
題目:統計下雨后的地面上有多少個水溝(相鄰八個格子為聯通)。分析:搜索,DFS。直接利用dfs搜索即可,找到的點賦值為'.'即可。說明:╮(╯▽╰)╭。#include #include char field[101][102];void dfs(int x, int y, int n, int m){ field[x][y] = '.'; for (int dx =
2016-06-17 23:32:25 369
原创 UVa 10920 - Spiral Tap
題目:在一個N*N(N為奇數)的方格里從中心開始蛇形填數字,問某個數字M的位置,左下角是(1,1)。分析:簡單題。首先開方判斷層數,然後分別判斷在四條邊上的那一條,分別處理。說明:╮(╯▽╰)╭。#include #include #include #include using namespace std;int main(){ int SZ, P; while (
2016-06-16 22:52:13 749
原创 UVa 12356 - Army Buddies
題目:有一排士兵,每次有一排子彈掃過(區間),輸出每次子彈掃過后兩端最近的人。分析:DS,雙向鏈錶。每次更新雙向鏈錶節點兩端的指針即可,定位時使用ID。說明:如果每次子彈的區間有交集,則此種方法會WA,需要用區間樹實現。#include #include #include #include #include using namespace std;int visit[1
2016-06-14 09:27:43 869
原创 UVa 10508 - Word Morphing
題目:有一些長度相同的字符串,從起始字符串每次改變一個字符,轉化成其他字符,求轉化順序。分析:簡單題。直接求出不同字符的個數排序輸出即可。說明:題目的條件都是迷惑的\(^o^)/~。#include #include #include #include using namespace std;char str[1001][1001];typedef struct _m
2016-06-12 12:08:26 575
原创 UVa 12032 - The Monkey and the Oiled Bamboo
題目:有一個梯子,從0層(地上)跳到頂上,梯子上面有一些位置要經過, 設置一個步長k層, 每次跳躍可以是k層或者是小於k的層數,如果跳了k層,則k就減少1,求最小的k。分析:模擬,貪心。直接逆向求解,每次遇到更大的或者相同的更新即可。說明:╮(╯▽╰)╭。#include #include int r[100001] = {0};int main()
2016-06-10 16:43:13 871
原创 UVa 11572 - Unique Snowflakes
題目:已知一串數字,從中取出最長的連續序列,其中沒有重複的數字。分析:數據結構。set是紅黑樹,O(lgN)的操作複雜度(插入、刪除、查找)。 用set存儲不含相同數字的連續串,遇到相同的就刪除前面所有數字,取最大的|set|。說明:忘記清空set導致WA了兩次╮(╯▽╰)╭。#include #include #include using names
2016-06-08 22:48:44 1025
原创 UVa 11413 - Fill the Containers
題目:給你一串連續的數字,連續的切割成m段,求每段和中最大的值的最小值。分析:貪心+二分。二分上限,可以證明每次可以盡量多的加和,只要不超過上限。說明:╮(╯▽╰)╭。#include #include int items[1111];int container_size(int size, int value){ int sum = 0, count = 1; for
2016-06-08 16:11:44 1775
原创 UVa 11360 - Have Fun with Matrices
題目:已知一個矩陣,在矩陣中做一些操作(轉置、交換行、交換列,整體自增或自減)輸出結果。分析:模擬。直接模擬輸出即可。說明:╮(╯▽╰)╭。#include #include #include #include #include using namespace std;char matrix[10][11];char operation[11];int main(
2016-06-08 11:38:33 1153
原创 UVa 11040 - Add bricks in the wall
題目:給你如題目的一個三角形,每個元素等於兩下面相鄰節點的和, 現在已知偶數層的偶數位置的值(這裡按0編號),求其他值。分析:簡單題。直接看圖找到計算公式即可。 设f(x,y)為第x層第y位置的元素值,則有如下計算公式: 偶數層奇數位置: f(2*i+2,2*j+1)= 0.5*(f(2*i,2*j)- f(2*i+
2016-06-04 10:52:45 923
原创 UVa 10304 - Optimal Binary Search Tree
題目:給定一串有序數字f,生成一個BST,使得Σ deep(i)* f(i)最小。分析:動態規劃,區間dp。按長度遞增枚舉區間。 狀態方程 f(s,e)= min(f(s,k-1)+ f(k+1,e)+ sum(s,e) - f(k))。說明:很久沒有寫dp了╮(╯▽╰)╭。#include #include int frequency[255];in
2016-06-02 12:45:17 993
SOFA: A Multi-Model Framework for Interactive Physical Simulation
2018-06-24
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人