Time of Update: 2018-12-05
#include <iostream>#include <cstdio>#include <string>#include <algorithm>#include <deque>#include <limits>#include <cmath>using namespace std;//求10進位正整數k的位元,如123為3位int nobits(int k){int count = 0,t = k;while(
Time of Update: 2018-12-05
二分搜尋的應用#include <iostream>#include <cstdio>#include <iomanip>using namespace std;int intCables[10002];//單位cmbool numberCuts(int index,int k,int length)//cm單位{long long lnums = 0;for (int i = 0; i < index; ++i){lnums += intCables[
Time of Update: 2018-12-05
註:修改完善於一個粗糙版本http://blog.csdn.net/aishen944/article/details/14835161,修改了原文代碼中的錯誤2,主要解決了在擴容時hash效率較差的問題 #ifndef _HASHTABLE_H #define _HASHTABLE_H struct hashtable; struct hashtable* hashtable_create(unsigned long size, unsigned
Time of Update: 2018-12-05
有兩種方法求解,(1)遞迴分解,這種方法很好想,但是逾時(2)分析題目,得出一些基本規律。(參考了他人的想法)1, a[1] > 1Proof: If a[1] = 1, a[t] could be replacedby a[t] + 1 and a[t]+1 > a[t] * 1. 2, 1 <= a[i+1] – a[i] <= 2Proof: If exists i make a[i+1] – a[i] >2, then a[i], a[i+1]
Time of Update: 2018-12-05
//Spell checker#include <iostream>#include <cstdio>#include <string>#include <set>using namespace std;set<string> dic;string dictxt[10005];int index = 0;bool isInDic(string& s){set<string>::iterator it;it =
Time of Update: 2018-12-05
-)常規解法,Time Limit Exceeded設一個點x與周圍8個點相減後絕對值的最大值為edv值。思想:1)同一行中的相鄰點x1,x2,如果x1已經求得它周圍的8個點那麼對於x2而言只需要計算另外3個點就可以了。 邊界情況就是:對於左邊界的點必須求周圍8個點2)當兩個相鄰點x1,x2的edv值都是0時,檢查是否存在接下來很多點值都相等的情況,這那麼可以加速。儘管使用了以上兩種技術但是速度仍然不夠快,平台通不過。#include <iostream>#include
Time of Update: 2018-12-05
#include <iostream>#include <cstdio>#include <string>#include <limits>#include <cmath>#include <algorithm>using namespace std;class Funk{public:typedef long long LL;typedef unsigned long long ULL;private:int nbits;
Time of Update: 2018-12-05
指向類成員的指標在C++語言中,可以定義一個指標,使其指向類成員或成員函數,然後通過指標來訪問類的成員。這包括指向屬性成員的指標和指向成員函數的指標。à 指向資料成員的指標在C++語言中,可以定義一個指標,使其指向類成員。當屬性成員為靜態和非靜態時,指標的使用也有不同。其中,指向非待用資料成員的指標定義格式如下:1. <資料類型> <類名>::*<指標名> [ =
Time of Update: 2018-12-05
Trees Made to Order#include <iostream>#include <cstdio>#include <string>using namespace std;const int LEN = 30;class OrderTree{private:static int kinds[LEN];//kinds[i]表示有i個結點情況下共有多少種不同的樹static int
Time of Update: 2018-12-05
以下為一熱心網友自己通過匿名類的形式實現Iterator介面,代碼如下所示:import java.util.Iterator;public class OurArrayList<E> implements Iterable<E> { private E[] datas; private int size; public OurArrayList() { this(16); }
Time of Update: 2018-12-05
//貪心演算法 #include <iostream>#include <cstdio>#include <list>#include <algorithm>using namespace std;typedef pair<int,int> PINTINT;bool cmp1(PINTINT p1, PINTINT p2){if (p1.first < p2.first)return true;if (p1.first >
Time of Update: 2018-12-05
解題思想:(x + step * m) % L = (y + step * n) % L則(x - y + step * (m - n) ) % L == 0 || ( y - x + step * (n - m)) % L == 0則(x - y + step * (m - n) ) = p * L || ( y - x + step * (n - m)) = p * L若m > n則相當於求 step * (m - n) + p * L = y - x
Time of Update: 2018-12-05
非常經典的8數位問題,主要採用的演算法是人工智慧中的“有序搜尋演算法”,也有人稱之為A演算法。#include <iostream>#include <cstdio>#include <algorithm>#include <set>#include <string>using namespace std;const int LEN = 9;struct PStatus{string pos;//位置資訊int index;//'x'
Time of Update: 2018-12-05
// iosfwd standard header#if _MSC_VER > 1000#pragma once#endif#ifndef _IOSFWD_#define _IOSFWD_#include <cstdio>#include <cstring>#include <cwchar>#include <xstddef>#ifdef _MSC_VER#pragma pack(push,8)#endif /*
Time of Update: 2018-12-05
#include <iostream>#include <cstdio>#include <string>#include <stack>using namespace std;class Navigation{private:stack<string> fward;stack<string> bward;string curl;//current urlpublic:Navigation(string url):curl(
Time of Update: 2018-12-05
原文來自:http://hi.baidu.com/gropefor/home 的部落格中,代碼寫的非常精巧,強烈推薦。在第二版的最佳化中使用了HashTable來加速查詢。這兩個代碼使我瞭解了兩種演算法,一種是雙向寬度優先搜尋,另一種就是實際的HashTable的應用,以前一直聽說HashTable很有用,但是從來沒有在自己實際的代碼中運用過,這一次開眼了。代碼一:雙廣搜
Time of Update: 2018-12-05
#include <iostream>#include <cstdio>#include <string>#include <algorithm>#include <map>using namespace std;map<string,int> dicm;//字典void myinit()//初始化字典{dicm.insert(make_pair("AA",5));dicm.insert(make_pair("AC",-1)
Time of Update: 2018-12-05
文章目錄 Parameters va_listType to holdinformation about variable argumentsThis type is used as a parameter for the macros definedin cstdarg to retrieve the additional arguments of a
Time of Update: 2018-12-05
第一次碰到最大流的問題。雖然我知道最大流的演算法,但是砬到這題是根本沒想到用最大流來求解。解法參考了http://www.cppblog.com/NARUTOACM/archive/2010/03/01/108680.html。解決此題的關鍵在於流圖的建立:1,源點Source為0,sink結點為T2,1 - m為要求m個不同的裝置3,m +1, m + n為室內已有的 n 個插頭receptacles4,m + n + 1 到
Time of Update: 2018-12-05
文章目錄 ParametersReturn value operator newvoid* operator new (std::size_t size) throw (std::bad_alloc);void* operator new (std::size_t size, const std::nothrow_t& nothrow_constant) throw();void* operator new