锘??xml version="1.0" encoding="utf-8" standalone="yes"?> hash_map錛岄【鍚嶆濅箟錛屽氨鏄埄鐢?/span>hash_set瀛樺偍緇撴瀯鐨勫啓map鏄犵収瀹瑰櫒錛屾櫘閫氱殑map鐢ㄧ殑鏄孩榛戞爲瀛樺偍緇撴瀯鍐欑殑銆傚厓绱犵殑媯绱㈡椂闂村姣旓紝hash_set榪戜技涓?/span>O(1)錛岀孩榛戞爲涓?/span>O(logn)銆?/span>Hash_map鐨勭┖闂村紑閿瑕佹瘮map 鐨勭┖闂村紑閿澶э紝灝ゅ叾鏄垜鐢ㄦ暟緇勬ā鎷熸寚閽堝啓鐨?/span>hash_map銆?/span> 鎵浠ワ紝濡傛灉鏈夊繀瑕侀噰鍙栨槧灝勭粨鏋勭殑鏃跺欙紝鑳界敤hash_map灝卞埆鐢?/span>map銆?/span> 闇瑕佹敞鎰忕殑鏄紝hash_map閬嶅巻鍑烘潵鐨勫厓绱犱笉鏄湁搴忕殑銆?/span> Hash_map鍜屾櫘閫?/span>hash_set鐩告瘮鐨勮瘽錛?/span>hash_map姣?/span>hash_set澶氫簡涓寮?/span>value琛紝涔熷氨鏄槧灝勮〃銆?/span> 涓嬮潰鏄?/span>hash_map鐨勬ā鏉匡紝鍜?/span>hash_set鐨勬ā鏉垮樊涓嶅銆?br />
class BinaryHeap
{
private:
int Size;
T * Tarr;
public:
BinaryHeap();
void insert(T x);
T deleteMin();
~BinaryHeap();
};
template<class T,int MAX>
BinaryHeap<T,MAX>::BinaryHeap()
{
Tarr=new T[MAX+1];
if(Tarr==NULL) {cout<<"鍒涘緩鏁扮粍澶辮觸"<<endl;return ;}
Size=0;
}
template<class T,int MAX>
void BinaryHeap<T,MAX>::insert(T x)
{
++Size;
if(Size==MAX) return;
int i;
for(i=Size;Tarr[i/2]>x;i/=2)
Tarr[i]=Tarr[i/2];
Tarr[i]=x;
}
template<class T,int MAX>
T BinaryHeap<T,MAX>::deleteMin()
{
if(Size==0) return 0;
T minem=Tarr[1];
T lastem=Tarr[Size--];
int i,child;
for(i=1;i*2<=Size;i=child)
{
child=i*2;
if(child!=Size-1&&Tarr[child+1]<Tarr[child])
++child;
if(lastem>Tarr[child])
Tarr[i]=Tarr[child];
else
break;
}
Tarr[i]=lastem;
return minem;
}
template<class T,int MAX>
BinaryHeap<T,MAX>::~BinaryHeap()
{
delete[] Tarr;
}
]]>
const int MAX=1000003;
template <class T>
class hash
{
private:
int pos;
int next[MAX];
int head[MAX];
T key[MAX];
public:
hash();
bool search(T x);
void push(T x);
};
template <class T>
hash<T>::hash()
{
pos=0;
memset(next,-1,sizeof(next));
memset(head,-1,sizeof(head));
//memset(key,-1,sizeof(key));
}
template <class T>
inline bool hash<T>::search(const T x)
{
int temp=x%MAX;
int t=head[temp];
while(t!=-1)
{
if (key[t]==x)
{
return 1;
}
t=next[t];
}
return 0;
}
template <class T>
inline void hash<T>::push(const T x)
{
int temp=x%MAX;
if (head[temp]!=-1)
{
next[pos]=head[temp];
}
head[temp]=pos;
key[pos]=x;
pos++;
}
]]>
struct HashFunction
{
int operator()(const KeyType& key)
{
int h=key%MaxHash;
if (h<0) h+=MaxHash;
return h;
}
};
template<class KeyType,class ValueType,int KeyContain,int MaxHash,class HashFun=HashFunction<KeyType,MaxHash> >
class HashMap
{
public:
HashMap():hashfun(){Clear();}
ValueType& operator[](const KeyType& key)
{
int h=hashfun(key);
int pos=head[h];
for(;pos!=0;pos=next[pos])
{
if(keys[pos]==key)
return values[pos];
}
next[++top]=head[h];
head[h]=top;
keys[top]=key;
values[top]=ValueType();//鍒濆鍖?/span>
++sz;
return values[top];
}
void Clear()
{
memset(head,0,sizeof(head));
memset(next,0,(top+1)*sizeof(int));
top=0;
sz=0;
}
unsigned int size() const {return sz;}
private:
unsigned int sz;
HashFun hashfun;
int head[MaxHash];
int next[KeyContain];
KeyType keys[KeyContain];
ValueType values[KeyContain];
int top;
};
]]>
#include<sstream>
#include<string>
using namespace std;
template<class out_type,class in_value>
out_type convert(const in_value & t)
{
stringstream stream;
stream<<t;//鍚戞祦涓紶鍊?/span>
out_type result;//榪欓噷瀛樺偍杞崲緇撴灉
stream>>result;//鍚憆esult涓啓鍏ュ?/span>
return result;
}
int main()
{
string s;
while(cin>>s)
{
double valdou=convert<double>(s);
int valint=convert<int>(s);
cout<<valdou<<endl;
cout<<valint<<endl;
}
return 0;
}
]]>
inline IntType ModPow(IntType m,IntType n,IntType p) //m鐨刵嬈℃柟妯
{
if(n==0) return 1;
if (n==1) return m%p;
IntType tmp=ModPow(m,n>>1,p);
return (tmp*tmp%p)*((n%2?m:1)%p)%p;
}
]]>