原创 【POJ】1321(DFS——棋盤問題)

棋盤問題Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 59850 Accepted: 28687Description在一個給定形狀的棋盤(形狀可能是不規則的)上面擺放

原创 【LeetCode】Two Sum (C++)

最近花了點時間瞭解了下C++,感覺與C還是有很多不同的。接下來堅持每天用C++寫五道LeetCode。fighting!題目:Given an array of integers, return indices of the two nu

原创 【C++】 生成隨機數

#include <iostream> #include<stdio.h> #include<time.h> #define random(x)(rand()%x) using namespace std; int main() {

原创 【HDU】2016 數據的交換輸出

Problem Description輸入n(n<100)個數,找出其中最小的數,將它與最前面的數交換後輸出這些數。 Input輸入數據有多組,每組佔一行,每行的開始是一個整數n,表示這個測試實例的數值的個數,跟着就是n個整數。n=0表示

原创 【POJ】1562 Oil Deposits(DFS)

DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp w

原创 【LeetCode】 Hamming Distance (C++)

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Give

原创 DFS——八個皇后—N個皇后的總結

1.八個皇后(指定n=8),輸出所有可能擺放的個數代碼:// // main.cpp // DFS——八個皇后自己寫 // // Created by showlo on 2018/4/14. // Copyright © 201

原创 【HDU】1016 DFS——Prime Ring Problem

Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle

原创 【POJ】1979 Black and Red(DFS)

Red and BlackTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 41057 Accepted: 22269DescriptionThere is a recta

原创 【HDU】2015 偶數求和

Problem Description有一個長度爲n(n<=100)的數列,該數列定義爲從2開始的遞增有序偶數,現在要求你按照順序每m個數求出一個平均值,如果最後不足m個,則以實際數量求平均值。編程輸出該平均值序列。 Input輸入數據有

原创 DFS——迷宮問題(輸出搜索過程及路徑長度)

題目與上一篇BFS是一樣的,這裏用DFS實現是爲了探究二者遍歷的區別。DFS代碼:// // main.cpp // DFS(迷宮問題自己寫)可輸出搜索過程 // // Created by showlo on 2018/4/14.

原创 DFS——求1—N所有數字的全排列

代碼:// // main.cpp // DFS——全排列 // // Created by showlo on 2018/4/14. // Copyright © 2018年 showlo. All rights reserve

原创 【LeetCode】Merge Two Binary Trees(C++)

Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are ov

原创 【LeetCode】136 Single Number(C++)

Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorit

原创 DFS——拯救OIBH總部

拯救OIBH總部(來源於http://acm.qust.edu.cn/problem.php?id=1101)OIBH被突來的洪水淹沒了> .< 還好OIBH總部有在某些重要的地方起一些圍牆,用*號表示,而一個封閉的*號區域洪水是進不去的