原创 usaco2.1.3-----Sorting a Three-Valued Sequence(*三值交換排序)
/* ID:lvfuan11 PROG:sort3 LANG:C++ translation: 有1,2,3三個數字組成的數列,現在要將其變成有序數列,求最少要交換多少次。 solution: 首先定義兩個數字如果交換後都在正確的位
原创 usaco2.1.2-----orderd fractions(歐幾裏的)
/* ID:lvfuan11 PROG:frac1 LANG:C++ */ #include <iostream> #include <cstdio> #include <vector> #include <algorithm> usi
原创 usaco2.1.1-----the castle(flood fill模型)
/* ID:lvfuan11 PROG:castle LANG:C++ translation: 見usanocow solution: flood fill的經典模型。dfs即可。注意題目要求選擇最靠西邊的牆,意味着同一個各自內,該
原创 usaco2.1.4
/* ID:lvfuan11 PROG:holstein LANG:C++ translation: 給出每頭牛需要的維生素,現在有若干種飼料,每種各含有若干量的各種維生素,問最少用多少種飼料可以滿足一頭牛的每日所需 solution
原创 usaco2.1.5
/* ID:lvfuan11 PROG:hamming LANG:C++ translation: 給出n,b,d求出n個字典序最小的n個長度爲b的01字符串,這些字符串兩兩滿足其hamming距離大於等於d。 solution:
原创 leetcode--3. Longest Substring Without Repeating Characters
題意: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcb
原创 leetcode--7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers.
原创 翻硬幣
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1000 +5; char str1[max
原创 九宮重排(BFS)
#include <iostream> #include <string> #include <queue> #include <set> using namespace std; struct Node { string code
原创 leetcode--1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may ass
原创 codeforces round#420
a題: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output
原创 leetcode--4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The
原创 hdu1069(*記憶化搜索)
/* translation: 給出n種類型的箱子,每種箱子數量可以無限供應。當一個箱子的底面長寬嚴格比另一個箱子要小時纔可以重疊在上面。 問最高可以疊多高? solution: 記憶化搜索即可 */ #inclu
原创 連號區間(*)
/* 感覺有點不科學,50000的數據量,n^2竟然能過,不可思議。。。 */ #include <iostream> #include <cstdio> #include <cstring> using namespace std;
原创 橫向打印二叉樹
問題描述 二叉樹可以用於排序。其原理很簡單:對於一個排序二叉樹添加新節點時,先與根節點比較,若小則交給左子樹繼續處理,否則交給右子樹。 當遇到空子樹時,則把該節點放入那個位置。 比如,10 8 5 7 12 4 的輸入順序,應該