锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
class deque {
public:
// typedefs:
typedef iterator;
typedef const_iterator;
typedef Allocator<T>::pointer pointer;
typedef Allocator<T>::reference reference;
typedef Allocator<T>::const_reference const_reference;
typedef size_type;
typedef difference_type;
typedef T value_type;
typedef reverse_iterator;
typedef const_reverse_iterator;
// allocation/deallocation:
deque();
deque(size_type n, const T& value = T());
deque(const deque<T, Allocator>& x);
template <class InputIterator>
deque(InputIterator first, InputIterator last);
~deque();
deque<T, Allocator>& operator=(const deque<T, Allocator>& x);
void swap(deque<T, Allocator>& x);
// accessors:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rend();
size_type size() const;
size_type max_size() const;
bool empty() const;
reference operator[](size_type n);
const_reference operator[](size_type n) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
// insert/erase:
void push_front(const T& x);
void push_back(const T& x);
iterator insert(iterator position, const T& x = T());
void insert (iterator position, size_type n, const T& x);
template <class InputIterator>
void insert (iterator position, InputIterator first, InputIterator last);
void pop_front();
void pop_back();
void erase(iterator position);
void erase(iterator first, iterator last);
};
]]>
class Allocator = allocator> class list
{
public:
// typedefs:
typedef iterator
typedef const_iterator
typedef Allocator<T>::pointer pointer
typedef Allocator<T>::reference reference
typedef Allocator<T>::const_reference const_reference
typedef size_type
typedef difference_type
typedef T value_type
typedef reverse_iterator
typedef const_reverse_iterator;
// allocation/deallocation:
list()
list(size_type n, const T& value = T())
template <class InputIterator>
list(InputIterator first, InputIterator last)
list(const list<T, Allocator>& x)
~list()
list<T, Allocator>& operator=(const list<T, Allocator>& x)
void swap(list<T, Allocator>& x);
// accessors:
iterator begin()
const_iterator begin() const
iterator end()
const_iterator end() const
reverse_iterator rbegin()
const_reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rend();
bool empty() const;
size_type size() const;
size_type max_size() const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
// insert/erase:
void push_front(const T& x);
void push_back(const T& x);
iterator insert(iterator position, const T& x = T());
void insert(iterator position, size_type n, const T& x);
template <class InputIterator>
void insert(iterator position, InputIterator first, InputIterator last);
void pop_front();
void pop_back();
void erase(iterator position);
void erase(iterator first, iterator last);
// special mutative operations on list:
void splice(iterator position, list<T, Allocator>& x);
void splice(iterator position, list<T, Allocator>& x, iterator i);
void splice(iterator position, list<T, Allocator>& x,
iterator first, iterator last);
void remove(const T& value);
template <class Predicate> void remove_if(Predicate pred);
void unique();
template <class BinaryPredicate> void unique(BinaryPredicate binary_pr
void merge(list<T, Allocator>& x);
template <class Compare> void merge(list<T, Allocator>& x, Compare com
void reverse();
void sort();
template <class Compare> void sort(Compare comp);
};
]]>
棰樻剰錛氬湪涓鏍嬫ゼ涓湁鑻ュ共鎴塊棿錛屼竴涓埧闂存湁鑻ュ共鎵囬棬閫氬線鍒殑鎴塊棿錛岀幇鍦ㄦ埧闂翠腑鏈変竴涓猻ecure room銆傜敱浜庢湁涓浜涙晫浜哄凡緇忔綔鍏ユ煇涓浜涙埧闂達(dá)紝鐜板湪闂叧闂渶灝戠殑涓浜涢棬錛屼嬌寰楁晫浜轟滑鍒拌揪涓嶄簡secure room銆傚浜庝竴鎵囬棬榪為欰-B錛岃嫢鎺у埗闈㈡澘CP鍦ˋ鏂癸紝鍒欐繪槸鍙互浠嶢->B錛屼絾鏄嫢鍏充笂闂紝鍒橞涓嶈兘鍒拌揪A銆?br> 瑙f硶錛氭渶澶ф祦銆傞鍏堥氳繃floyd綆楁硶鍒ゆ柇鏄惁鏁屼漢鎬繪槸鍙互鍒拌揪secure room錛屽鏋滆兘鐩存帴杈撳嚭緇撴灉錛涘鏋滀笉鑳斤紝鍒欓氳繃鏈澶ф祦綆楁硶姹傝В鍗沖彲銆傚浜庝竴鎵囬棬A-B錛孋P鍦ˋ鏂瑰垯浠嶢榪炰竴鏉℃湁鍚戣竟鍒癇錛屽閲忎負(fù)鏃犵┓澶э紝浠嶣榪炰竴鏉¤竟鍒癆錛屽閲忎負(fù)1銆備袱涓埧闂翠箣闂村彲鑳芥湁澶氭墖闂紝杈圭殑瀹歸噺绱姞鍗沖彲銆傚鍔犱竴涓簮鐐癸紝浠庢簮鐐硅繛杈瑰埌鏈夋晫浜虹殑鎴塊棿錛屽閲忎負(fù)1銆傚鍥炬眰鏈澶ф祦鍗充負(fù)緇撴灉銆?br>浠g爜濡備笅錛?br>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 22
#define inf 1000000
int map[MAXN][MAXN];
int flow[MAXN][MAXN];
int max_flow(int n,int mat[][MAXN],int source,int sink,int flow[][MAXN]){
int pre[MAXN],que[MAXN],p,q,t,i,j;
int d[MAXN];
int tmp;
if (source==sink) return inf;
for (i=0;i<n;i++)
for (j=0;j<n;flow[i][j++]=0);
for (;;){
for (i=0;i<n;pre[i++]=0);
pre[t=source]=source+1,d[t]=inf;
for (p=q=0;p<=q&&!pre[sink];t=que[p++])
for (i=0;i<n;i++)
if (!pre[i]&&(tmp=mat[t][i]-flow[t][i]))
pre[que[q++]=i]=t+1,d[i]=d[t]<tmp?d[t]:tmp;
else if (!pre[i]&&(tmp=flow[i][t]))
pre[que[q++]=i]=-t-1,d[i]=d[t]<tmp?d[t]:tmp;
if (!pre[sink]) break;
for (i=sink;i!=source;)
if (pre[i]>0)
flow[pre[i]-1][i]+=d[sink],i=pre[i]-1;
else
flow[i][-pre[i]-1]-=d[sink],i=-pre[i]-1;
}
tmp = 0;
for (i=0;i<n;tmp+=flow[source][i++]);
return tmp;
}
int main()
{
int T, n, m, k, y;
char str[3];
int d[MAXN];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
n++;
memset(map,0,sizeof(map));
memset(flow,0,sizeof(flow));
for(int i = 1; i <= m; i++){
scanf("%s %d",str, &k);
d[i] = (strlen(str) == 1);
if(d[i])map[0][i] = inf;
for(int j = 0; j < k; j++){
scanf("%d",&y);
y++;
flow[i][y] = 1;
map[i][y] += inf;
map[y][i] += 1;
}
}
// Checking always exists a path to secure room. Output "PANIC ROOM BREACH"!
for(k = 1; k <= m; k++)
for(int i = 1; i <= m; i++)
for(int j = 1; j <= m; j++)
if(flow[i][k]&&flow[k][j])
flow[i][j] = 1;
for(k = 1; k <= m && !(d[k] && flow[k][n]); k++);
if(k <= m)
printf("PANIC ROOM BREACH\n");
else
printf("%d\n", max_flow(m+1,map,0,n,flow));
}
return 0;
}
]]>
double log10(double x) 榪斿洖log10x鐨勫?浠?0涓哄簳鐨勫鏁?br>double pow(double x,double y) 榪斿洖x^y鐨勫?br>double pow10(int p) 榪斿洖10^p鐨勫?br>double sqrt(double x) 榪斿洖a,涓攁婊¤凍a*a=x,a>=0
double acos(double x) 榪斿洖x鐨勫弽浣欏雞cos^-1(x)鍊?x涓哄姬搴?br>double asin(double x) 榪斿洖x鐨勫弽姝e雞sin^-1(x)鍊?x涓哄姬搴?br>double atan(double x) 榪斿洖x鐨勫弽姝e垏tan^-1(x)鍊?x涓哄姬搴?br>double atan2(double y,double x) 榪斿洖y/x鐨勫弽姝e垏tan^-1(x)鍊?y鐨剎涓哄姬搴?br>double cos(double x) 榪斿洖x鐨勪綑寮os(x)鍊?x涓哄姬搴?br>double sin(double x) 榪斿洖x鐨勬寮in(x)鍊?x涓哄姬搴?br>double tan(double x) 榪斿洖x鐨勬鍒噒an(x)鍊?x涓哄姬搴?br>double cosh(double x) 榪斿洖x鐨勫弻鏇蹭綑寮osh(x)鍊?x涓哄姬搴?br>double sinh(double x) 榪斿洖x鐨勫弻鏇叉寮inh(x)鍊?x涓哄姬搴?br>double tanh(double x) 榪斿洖x鐨勫弻鏇叉鍒噒anh(x)鍊?x涓哄姬搴?br>double hypot(double x,double y) 榪斿洖鐩磋涓夎褰㈡枩杈圭殑闀垮害(z),x鍜寉涓虹洿瑙掕竟鐨勯暱搴?z^2=x^2+y^2
double ceil(double x) 榪斿洖涓嶅皬浜巟鐨勬渶灝忔暣鏁?br>double floor(double x) 榪斿洖涓嶅ぇ浜巟鐨勬渶澶ф暣鏁?br>void srand(unsigned seed) 鍒濆鍖栭殢鏈烘暟鍙戠敓鍣?br>int rand() 浜х敓涓涓殢鏈烘暟騫惰繑鍥炶繖涓暟
double poly(double x,int n,double c[])浠庡弬鏁頒駭鐢熶竴涓欏瑰紡
double modf(double value,double *iptr)灝嗗弻綺懼害鏁皏alue鍒嗚В鎴愭暣鏁伴儴鍒嗗拰灝忔暟閮ㄥ垎錛宨ptr涓烘暣鏁伴儴鍒嗭紝榪斿洖灝忔暟閮ㄥ垎
double fmod(double x,double y) 榪斿洖x/y鐨勪綑鏁?br>double atof(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愭誕鐐規(guī)暟騫惰繑鍥炶繖涓誕鐐規(guī)暟
double atoi(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愭暣鏁板茍榪斿洖榪欎釜鏁存暟
double atol(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愰暱鏁存暟騫惰繑鍥炶繖涓暣鏁?br>char *ecvt(double value,int ndigit,int *decpt,int *sign)灝嗘誕鐐規(guī)暟value杞崲鎴愬瓧絎︿覆騫惰繑鍥炶瀛楃涓?br>char *fcvt(double value,int ndigit,int *decpt,int *sign)灝嗘誕鐐規(guī)暟value杞崲鎴愬瓧絎︿覆騫惰繑鍥炶瀛楃涓?br>char *gcvt(double value,int ndigit,char *buf)灝嗘暟value杞崲鎴愬瓧絎︿覆騫跺瓨浜巄uf涓?騫惰繑鍥瀊uf鐨勬寚閽?br>char *ultoa(unsigned long value,char *string,int radix)灝嗘棤絎﹀彿鏁村瀷鏁皏alue杞崲鎴愬瓧絎︿覆騫惰繑鍥炶瀛楃涓?radix涓鴻漿鎹㈡椂鎵鐢ㄥ熀鏁?br>char *ltoa(long value,char *string,int radix)灝嗛暱鏁村瀷鏁皏alue杞崲鎴愬瓧絎︿覆騫惰繑鍥炶瀛楃涓?radix涓鴻漿鎹㈡椂鎵鐢ㄥ熀鏁?br>char *itoa(int value,char *string,int radix)灝嗘暣鏁皏alue杞崲鎴愬瓧絎︿覆瀛樺叆string,radix涓鴻漿鎹㈡椂鎵鐢ㄥ熀鏁?br>double atof(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愬弻綺懼害鏁?騫惰繑鍥炶繖涓暟,閿欒榪斿洖0
int atoi(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愭暣鍨嬫暟, 騫惰繑鍥炶繖涓暟,閿欒榪斿洖0
long atol(char *nptr) 灝嗗瓧絎︿覆nptr杞崲鎴愰暱鏁村瀷鏁?騫惰繑鍥炶繖涓暟,閿欒榪斿洖0
double strtod(char *str,char **endptr)灝嗗瓧絎︿覆str杞崲鎴愬弻綺懼害鏁?騫惰繑鍥炶繖涓暟,
long strtol(char *str,char **endptr,int base)灝嗗瓧絎︿覆str杞崲鎴愰暱鏁村瀷鏁?騫惰繑鍥炶繖涓暟,
int matherr(struct exception *e)鐢ㄦ埛淇敼鏁板閿欒榪斿洖淇℃伅鍑芥暟
double _matherr(_mexcep why,char *fun,double *arg1p,
double *arg2p,double retval)鐢ㄦ埛淇敼鏁板閿欒榪斿洖淇℃伅鍑芥暟
unsigned int _clear87() 娓呴櫎嫻偣鐘舵佸瓧騫惰繑鍥炲師鏉ョ殑嫻偣鐘舵?br>void _fpreset()閲嶆柊鍒濅嬌鍖栨誕鐐規(guī)暟瀛︾▼搴忓寘
unsigned int _status87() 榪斿洖嫻偣鐘舵佸瓧
]]>
bool includes(InputIterator1 first1, InputIterator1 last1,InputIterator2 first2, InputIterator2 last2, Compare comp)
鍚堝茍錛氬悎騫禰first1,last1)涓嶽first2,last2)涓や釜闆嗗悎銆?br>OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
姹備氦闆嗭細(xì)姹俒first1,last1)涓嶽first2,last2)涓や釜闆嗗悎鐨勪氦闆嗐?
OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
姹傚樊錛氭眰鍦╗first1,last1)涓紝鑰屼笉鍦╗first2,last2)鐨勫厓绱犻泦鍚堛?
OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
姹傚縐板樊錛氫袱涓泦鍚堜箣鍜岄泦 鍑忓幓 涓や釜闆嗗悎涔嬩氦闆嗐?
OutputIterator set_symmetric difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
OutputIterator set_symmetric difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
#include<algorithm>
#include<vector>
#include<iterator>
using namespace std;
void init(vector<int>& v, int a, int b)
{
v.clear();
for(int i = a; i <= b; i++){
v.push_back(i);
}
}
int main()
{
vector<int>v1, v2;
vector<int>::iterator itr;
cout << "Includes operator:" << endl;
init(v1,1,5);
init(v2,1,8);
cout << "Vector v1: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "Vector v2: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "v2 is in v1 ? " << (includes(v1.begin(),v1.end(),v2.begin(),v2.end()) ? "yes" : "no") << endl;
cout << "v1 is in v2 ? " << (includes(v2.begin(),v2.end(),v1.begin(),v1.end()) ? "yes" : "no") << endl;
cout << endl;
init(v1,1,5);
init(v2,3,8);
cout << "Vector v1: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "Vector v2: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_union operator on v1,v2: ";
set_union(v1.begin(),v1.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
init(v1,1,5);
init(v2,3,8);
cout << "Vector v1: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "Vector v2: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_intersecion operator on v1,v2: ";
set_intersection(v1.begin(),v1.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
init(v1,1,5);
init(v2,3,8);
cout << "Vector v1: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "Vector v2: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_difference operator, v1 to v2: ";
set_difference(v1.begin(),v1.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_difference operator, v2 to v1: ";
set_difference(v2.begin(),v2.end(),v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
init(v1,1,5);
init(v2,3,8);
cout << "Vector v1: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "Vector v2: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_symmetric_difference operator, v1 to v2: ";
set_symmetric_difference(v1.begin(),v1.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "set_symmetric_difference operator, v2 to v1: ";
set_symmetric_difference(v2.begin(),v2.end(),v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
return 0;
}
Vector v1: 1 2 3 4 5
Vector v2: 1 2 3 4 5 6 7 8
v2 is in v1 ? no
v1 is in v2 ? yes
Vector v1: 1 2 3 4 5
Vector v2: 3 4 5 6 7 8
set_union operator on v1,v2: 1 2 3 4 5 6 7 8
Vector v1: 1 2 3 4 5
Vector v2: 3 4 5 6 7 8
set_intersecion operator on v1,v2: 3 4 5
Vector v1: 1 2 3 4 5
Vector v2: 3 4 5 6 7 8
set_difference operator, v1 to v2: 1 2
set_difference operator, v2 to v1: 6 7 8
Vector v1: 1 2 3 4 5
Vector v2: 3 4 5 6 7 8
set_symmetric_difference operator, v1 to v2: 1 2 6 7 8
set_symmetric_difference operator, v2 to v1: 1 2 6 7 8
]]>
OutputIterator merge (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
OutputIterator merge (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
inplace_merge鍚堝茍涓涓腑鍓嶅悗涓ゆ鍒嗗埆鏈夊簭鐨勫簭鍒楋紝鍗砙first,middle)涓嶽middle,last)鍒嗗埆鏈夊簭錛屽悎騫惰繖涓や釜瀛愬簭鍒楋紝騫舵妸緇撴灉淇濆瓨鍦╗first,last錛変腑銆?br>inplace_merge (BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
inplace_merge (BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
#include<algorithm>
#include<iostream>
#include<iterator>
#include<vector>
using namespace std;
int main()
{
vector<int>v1;
vector<int>v2;
vector<int>v3;
vector<int>::iterator vecitr;
for(int i = 1; i <= 10; i++){
v1.push_back(i%7);
v2.push_back(i%4);
}
sort(v1.begin(),v1.end());
cout << "Fisrt vecter: ";
copy(v1.begin(),v1.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
sort(v2.begin(),v2.end());
cout << "Second vecter: ";
copy(v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
cout << "Merge this two vecter: ";
merge(v1.begin(),v1.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
for(int i = 1; i <= 10; i++){
v3.push_back(i%7);
}
sort(v3.begin(),v3.end());
int x = v3.size();
for(int i = 1; i <= 10; i++){
v3.push_back(i%4);
}
vecitr = v3.begin();
advance(vecitr,x);
sort(vecitr,v3.end());
cout << "Third vecter: ";
copy(v3.begin(),v3.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
cout << "inplace_Merge third vecter: ";
inplace_merge(v3.begin(),vecitr,v3.end());
copy(v3.begin(),v3.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
return 0;
}
Second vecter: 0 0 1 1 1 2 2 2 3 3
Merge this two vecter: 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 5 6
Third vecter: 0 1 1 2 2 3 3 4 5 6 0 0 1 1 1 2 2 2 3 3
inplace_Merge third vecter: 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 5 6
]]>
ForwardIterator lower_bound (ForwardIterator first,ForwardIterator last, const T& value)
ForwardIterator lower_bound (ForwardIterator first,ForwardIterator last, const T& value, Compare comp)
//鏌ユ壘鏈榪滅殑涓涓猧terator i錛?浣垮緱[first,i)閲岄潰鐨勪換鎰忎竴涓猧terator j錛屾湁 *j < value or comp(*j,value)==true.
ForwardIterator upper_bound (ForwardIterator first,ForwardIterator last, const T& value)
ForwardIterator upper_bound (ForwardIterator first,ForwardIterator last, const T& value, Compare comp)
//鏌ユ壘鏈榪滅殑涓涓猧terator i錛?浣垮緱[first,i)閲岄潰鐨勪換鎰忎竴涓猧terator j錛屾湁 !(*j < value) or comp(*j,value)==false.
pair equal_range(ForwardIterator first, ForwardIterator last, const T& value)
pair equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp)
//鏌ユ壘鏈澶х殑subrange[i,j)錛屼嬌寰椾換鎰忎竴涓猧terator in [i,j)婊¤凍!(*k<value) && !(value<*k) or comp(*k,value)==false && comp(value,*k)==false.
bool binary_search (ForwardIterator first, ForwardIterator last, const T& value)
bool binary_search (ForwardIterator first, ForwardIterator last, const T& value, Compare comp)
// 鏌ユ壘鏄惁鍦╗first,last)涓瓨鍦╥terator i,婊¤凍 !(*i<value) && !(value<*i) or comp(*i,value)==false && comp(value,*i)==false
// 瀛樺湪鍒欒繑鍥瀟rue,鍚﹀垯榪斿洖false.
#include<iostream>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
vector<int>v;
vector<int>::iterator itr;
pair< vector<int>::iterator, vector<int>::iterator >vecpair;
for(int i = 1; i <= 20; i++){
v.push_back(i%6);
}
sort(v.begin(),v.end());
cout << "array: " << endl << " ";
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
cout << endl;
//lower_bound
cout << "lower_bound function, value = 3:" << endl;
itr = lower_bound(v.begin(),v.end(),3);
cout << " [first, itr) = ";
copy(v.begin(),itr,ostream_iterator<int>(cout," "));
cout << endl;
cout << " [itr, last) = ";
copy(itr,v.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
// upper_bound
cout << "upper_bound function, value = 3:" << endl;
itr = upper_bound(v.begin(),v.end(),3);
cout << " [first, itr) = ";
copy(v.begin(),itr,ostream_iterator<int>(cout," "));
cout << endl;
cout << " [itr, last) = ";
copy(itr,v.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
// equal_range
cout << "equal_range function, value = 3:" << endl;
vecpair = equal_range(v.begin(),v.end(),3);
cout << " [vecpair->first, vecpair->second) = ";
copy(vecpair.first, vecpair.second, ostream_iterator<int>(cout," "));
cout << endl << endl;
//binary_search, value = 3
cout << "binary_search function, value = 3:" << endl;
cout << "3 is " << (binary_search(v.begin(),v.end(),3) ? "":"not ") << "in array." << endl;
cout << endl;
//binary_search, value = 6
cout << "binary_search function, value = 6:" << endl;
cout << "6 is " << (binary_search(v.begin(),v.end(),6) ? "":"not ") << "in array." << endl;
cout << endl;
return 0;
}
0 0 0 1 1 1 1 2 2 2 2 3 3 3 4 4 4 5 5 5
lower_bound function, value = 3:
[first, itr) = 0 0 0 1 1 1 1 2 2 2 2
[itr, last) = 3 3 3 4 4 4 5 5 5
upper_bound function, value = 3:
[first, itr) = 0 0 0 1 1 1 1 2 2 2 2 3 3 3
[itr, last) = 4 4 4 5 5 5
equal_range function, value = 3:
[vecpair->first, vecpair->second) = 3 3 3
binary_search function, value = 3:
3 is in array.
binary_search function, value = 6:
6 is not in array.
]]>
sscanf( s, “%[a-z]”, string ) ; // string=hello
%[^a-z] 璇誨彇涓嶅湪a-z涔嬮棿鐨勫瓧絎︿覆錛屽鏋滅鍒癮-z涔嬮棿鐨勫瓧絎﹀垯鍋滄錛屽
char s[]="HELLOkitty” ; // 娉ㄦ剰: ,閫楀彿鍦ㄤ笉 a-z涔嬮棿
sscanf( s, “%[^a-z]”, string ) ; // string=HELLO
%*[^=] 鍓嶉潰甯?* 鍙瘋〃紺轟笉淇濆瓨鍙橀噺,璺寵繃絎﹀悎鏉′歡鐨勫瓧絎︿覆銆?br> char s[]="notepad=1.0.0.1001" ;
char szfilename [32] = "" ;
int i = sscanf( s, "%*[^=]", szfilename ) ; // szfilename=NULL,鍥犱負(fù)娌′繚瀛?br> int i = sscanf( s, "%*[^=]=%s", szfilename ) ; // szfilename=1.0.0.1001
]]>