algorithm之不变序列操作
概述:不变序列算法,参见http://www.cplusplus.com/reference/algorithm/
- /*
- std::for_each
- template <class InputIterator, class Function>
- Function for_each (InputIterator first, InputIterator last, Function fn);
- Apply function to range
- Applies function fn to each of the elements in the range [first,last).
- [对[first, last)中的所有元素调用函数fn]
- The behavior of this template function is equivalent to:
- [该模板函数的行为与以下操作等价:]
- template<class InputIterator, class Function>
- Function for_each(InputIterator first, InputIterator last, Function fn)
- {
- while (first!=last) {
- fn (*first);
- ++first;
- }
- return fn; // or, since C++11: return move(fn);
- }
- */
- #include <iostream>
- #include <vector>
- #include <algorithm>
- class myclass
- {
- public:
- void operator() (int i)
- {
- std::cout<<' '<<i;
- }
- };
- void myfunctoin (int i)
- {
- std::cout<<' '<<i;
- }
- int main()
- {
- std::vector<int> myvec;
- std::vector<int>::iterator it;
- for(int i=; i<; i++)
- myvec.push_back(i+);
- std::cout<<"myvec contains:";
- for_each(myvec.begin(), myvec.end(), myfunctoin);
- std::cout<<'\n';
- //or
- myclass obj;
- std::cout<<"myvec contains:";
- for_each(myvec.begin(), myvec.end(), obj);
- std::cout<<'\n';
- system("pause");
- return ;
- }
- /*
- std::find
- template <class InputIterator, class T>
- InputIterator find (InputIterator first, InputIterator last, const T& val);
- Find value in range
- Returns an iterator to the first element in the range [first,last) that compares equal to val. If no such element is found, the function returns last.
- [返回[first, last)中第一个指向val的迭代器,如果没有找到则返回last]
- The function uses operator== to compare the individual elements to val.
- [该函数使用operator==来比较元素元素是否为val]
- The behavior of this function template is equivalent to:
- [该模板函数的行为与以下操作等价:]
- template<class InputIterator, class T>
- InputIterator find (InputIterator first, InputIterator last, const T& val)
- {
- while(first != last){
- if(*first == val) return first;
- ++first;
- }
- return last;
- }
- */
- #include <iostream>
- #include <vector>
- #include <algorithm>
- int main()
- {
- // using std::find with array and pointer.
- int myints[] = {, , , };
- int *p;
- p = std::find(myints, myints+, );
- if(p != myints+)
- std::cout<<"Element found in myints: "<<*p<<'\n';
- else
- std::cout<<"Element not found in myints\n";
- // using std::find with vector and iterator.
- std::vector<int> myvector (myints, myints+);
- std::vector<int>::iterator it;
- it = std::find(myvector.begin(), myvector.end(), );
- if(it != myvector.end())
- std::cout<<"Element found in myints: "<<*it<<'\n';
- else
- std::cout<<"Element not found in myints\n";
- system("pause");
- return ;
- }
- /*
- std::find_if
- template<class InputIterator, class UnaryPredicate>
- InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);
- Find element in range
- Returns an iterator to the first element in the range [first,last) for which pred returns true. If no such element is found, the function returns last.
- [返回[first, last)中第一个使得pred返回真的迭代器,如果没有找到,则返回last]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class InputIterator, class UnaryPredicate>
- InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred)
- {
- while(first != last){
- if(pred(*first)) return first;
- ++first;
- }
- return last;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- bool IsOdd (int i)
- {
- return ((i%) == );
- }
- int main()
- {
- std::vector<int> myvector;
- myvector.push_back();
- myvector.push_back();
- myvector.push_back();
- myvector.push_back();
- std::vector<int>::iterator it = std::find_if(myvector.begin(), myvector.end(), IsOdd);
- if(it != myvector.end())
- std::cout<<"The first odd value in myvector is "<<*it<<'\n';
- else
- std::cout<<"There is no odd value in myvector."<<'\n';
- system("pause");
- return ;
- }
- /*
- //std::adjacent_find
- template <class FowardIterator>
- FowardIterator adjacent_find (FowardIterator first, FowardIterator last);
- template <class FowardIterator, class BinaryPredicate>
- FowardIterator adjacent_find (FowardIterator first, FowardIterator last, BinaryPredicate pred);
- Find equal adjacent elements in range
- Searches the range [first,last) for the first occurrence of two consecutive elements that match, and returns an iterator to the first of these two elements, or last if no such pair is found.
- [在[fisrt, last)中寻找第一次匹配成功的两个连续元素,并返回指向其中第一个元素的迭代器,如果没有匹配成功,则返回last]
- Two elements match if they compare equal using operator== (or using pred, in version (2)).
- [默认使用operator==来判断两个元素是否匹配成功,或者使用pred来判断]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class FowardIterator>
- FowardIterator adjacent_find (FowardIterator first, FowardIterator last)
- {
- if(first != last)
- {
- FowardIterator next = first;
- ++next;
- while(next != last){
- if(*first == *next) return first;
- ++first; ++next;
- }
- return last;
- }
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- bool myfunctoin(int i, int j)
- {
- return (i == j);
- }
- int main()
- {
- int myints[] = {, , , , , , , , };
- std::vector<int> myvector(myints, myints+);
- std::vector<int>::iterator it;
- it = std::adjacent_find(myvector.begin(), myvector.end());
- if(it != myvector.end())
- std::cout<<"The first pair of repeated elements are "<<*it<<'\n';
- it = std::adjacent_find(++it, myvector.end(), myfunctoin);
- if(it != myvector.end())
- std::cout<<"The second pair of repeated elements are "<<*it<<'\n';
- system("pause");
- return ;
- }
- /*
- std::find_end
- template <class ForwardIterator1, class ForwardIterator2>
- ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);
- template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
- ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
- Find last subsequence in range
- Searches the range [first1,last1) for the last occurrence of the sequence defined by [first2,last2), and returns an iterator to its first element, or last1 if no occurrences are found.
- [在序列[first1, last2)中搜索出最后一个与序列[first2, last2)相匹配的子序列,并返回指向搜索到的子序列的第一个元素的迭代器,如果没有搜索到则返回last1]
- The elements in both ranges are compared sequentially using operator== (or pred, in version (2)): A subsequence of [first1,last1) is considered a match only when this is true for all the elements of [first2,last2).
- [比较两个序列中的元素是通过operator==来进行的(或者使用pred)]
- This function returns the last of such occurrences. For an algorithm that returns the first instead, see search.
- [该函数按返回的是最后一个匹配的子序列,如果想要得到第一个匹配的子序列,请看search算法]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class ForwardIterator1, class ForwardIterator2>
- ForwardIterator1 find_end (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
- {
- if (first2==last2) return last1; // specified in C++11
- ForwardIterator1 ret = last1;
- while(first1 != last1)
- {
- ForwardIterator1 it1 = first1;
- ForwardIterator2 it2 = first2;
- while(*it1 == *it2){ // or: while (pred(*it1,*it2)) for version (2)
- ++it1; ++it2;
- if(it2 == last2) {ret = first1; break;}
- if(it1 == last1) return ret;
- }
- ++first1;
- }
- return ret;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- bool myfunctoin(int i, int j){
- return (i==j);
- }
- int main()
- {
- int myints[] = {, , , , , , , , , };
- std::vector<int> myvector(myints, myints+);
- int needle1[] = {, , };
- // using default comparison.
- std::vector<int>::iterator it;
- it = std::find_end(myvector.begin(), myvector.end(), needle1, needle1+);
- if(it != myvector.end())
- std::cout<<"needle1 last found at position "<<(it - myvector.begin())<<'\n';
- int needle2[] = {, , };
- // using predicate comparison.
- it = std::find_end(myvector.begin(), myvector.end(), needle2, needle2+, myfunctoin);
- if(it != myvector.end())
- std::cout<<"needle2 last found at position "<<(it - myvector.begin())<<'\n';
- system("pause");
- return ;
- }
- /*
- std::find_first_of
- template <class ForwardIterator1, class ForwardIterator2>
- ForwardIterator1 find_first_of (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);
- template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
- ForwardIterator1 find_first_of (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
- Find element from set in range
- Returns an iterator to the first element in the range [first1,last1) that matches any of the elements in [first2,last2). If no such element is found, the function returns last1.
- [返回指向[first1, last1)中第一个与[first2, last2)中任一元素相匹配的元素的迭代器,如果没有找到则返回last1]]
- The elements in [first1,last1) are sequentially compared to each of the values in [first2,last2) using operator== (or pred, in version (2)), until a pair matches.
- [元素的比较是通过operator==来进行的(或者通过pred)]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class ForwardIterator1, class ForwardIterator2>
- ForwardIterator1 find_first_of (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2)
- {
- while(first1 != last1){
- for(ForwardIterator2 it2 = first2; it2 != last2; ++it2){
- if(*it2 == *first1) // or: if (pred(*it,*first)) for version (2)
- return first1;
- }
- ++first1;
- }
- return last1;
- }
- */
- #include <iostream> // std::cout
- #include <algorithm> // std::find_first_of
- #include <vector> // std::vector
- #include <cctype> // std::tolower
- bool comp_case_insensitive (char c1, char c2) {
- return (std::tolower(c1)==std::tolower(c2));
- }
- int main () {
- int mychars[] = {'a','b','c','A','B','C'};
- std::vector<char> haystack (mychars,mychars+);
- std::vector<char>::iterator it;
- int needle[] = {'A','B','C'};
- // using default comparison:
- it = find_first_of (haystack.begin(), haystack.end(), needle, needle+);
- if (it!=haystack.end())
- std::cout << "The first match is: " << *it << '\n';
- // using predicate comparison:
- it = find_first_of (haystack.begin(), haystack.end(),
- needle, needle+, comp_case_insensitive);
- if (it!=haystack.end())
- std::cout << "The first match is: " << *it << '\n';
- system("pause");
- return ;
- }
- /*
- std::equal
- template <class InputItertor1, class InputIterator2>
- bool equal (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
- template <class InputIterator1, class InputIterator2, class BinaryPredicate>
- bool equal (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred);
- Test whether the elements in two ranges are equal
- [比较两个范围中的元素是否相等]
- Compares the elements in the range [first1,last1) with those in the range beginning at first2, and returns true if all of the elements in both ranges match.
- [将[first1, last1)中的元素与以first2为起点的相同范围内的元素进行比较,如果两个范围中的元素全部相等则返回真]
- The elements are compared using operator== (or pred, in version (2)).
- [元素间通过operator==进行比较(或者使用pred)]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class InputIterator1, class InputIterator2>
- bool equal (InputIterator1 first1, InputIterator2 last1, InputIterator2 first2)
- {
- while(first1 != last1){
- if(!(*first1 == *first2)) // or: if (!pred(*first1,*first2)), for version 2
- return false;
- ++first1; ++first2;
- }
- return true;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- bool mypredicate(int i, int j)
- {
- return (i == j);
- }
- int main()
- {
- int myints[] = {, , , , };
- std::vector<int> myvector(myints, myints+);
- if(std::equal(myvector.begin(), myvector.end(), myints))
- std::cout<<"The contents of both sequences are equal.\n";
- else
- std::cout<<"The contents of both sequences differ.\n";
- myvector[] = ;
- if(std::equal(myvector.begin(), myvector.end(), myints, mypredicate))
- std::cout<<"The contents of both sequences are equal.\n";
- else
- std::cout<<"The contents of both sequences differ.\n";
- system("pause");
- return ;
- }
- /*
- std::mismatch
- template <class InputIterator1, class InputIterator2>
- pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator1 first2);
- template <class InputIterator1, class InputIterator2, class BinaryPredicate>
- pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator1 first2, BinaryPredicate pred);
- Return first position where two ranges differ
- Compares the elements in the range [first1,last1) with those in the range beginning at first2, and returns the first element of both sequences that does not match.
- [比较[first1, last1)与[fist2, last2)之间的元素,并返回两者第一个不匹配的元素]
- The elements are compared using operator== (or pred, in version (2)).
- [元素间的比较通过operator==来进行(或者通过pred)]
- The function returns a pair of iterators to the first element in each range that does not match.
- [该函数的返回值类型是pair,其中的两个参数是指向两个区间中不匹配元素的迭代器]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class InputIterator1, class InputIterator2>
- pair<InputIterator1, InputIterator2> mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 )
- {
- while ( (first1!=last1) && (*first1==*first2) ) // or: pred(*first1,*first2), for version 2
- { ++first1; ++first2; }
- return std::make_pair(first1,first2);
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <utility> //std::pair
- bool mypredicate(int i, int j){
- return (i==j);
- }
- int main()
- {
- std::vector<int> myvector;
- for(int i=; i<; i++) myvector.push_back(i*);
- int myints[] = {, , , , };
- std::pair<std::vector<int>::iterator, int*> mypair;
- // using default comparison
- mypair = std::mismatch(myvector.begin(), myvector.end(), myints);
- std::cout<<"First mismatch elements: "<<*mypair.first<<" and "<<*mypair.second<<'\n';
- // using predicate comparison
- mypair = std::mismatch(++mypair.first, myvector.end(), ++mypair.second, mypredicate);
- std::cout<<"Second mismatch elements: "<<*mypair.first<<" and "<<*mypair.second<<'\n';
- system("pause");
- return ;
- }
- /*
- template <class ForwardIterator1, class ForwardIterator2>
- ForwardIterator1 search (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator1 first2, ForwardIterator1 last2);
- template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
- ForwardIterator1 search (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator1 first2, ForwardIterator1 last2, BinaryPredicate pred);
- Search range for subsequence
- Searches the range [first1,last1) for the first occurrence of the sequence defined by [first2,last2), and returns an iterator to its first element, or last1 if no occurrences are found.
- [在[first1, last1)中搜索第一个与序列[first2, last2)相匹配的子序列,并返回指向搜索到的子序列的第一个元素的迭代器,如果没有搜索到则返回last1]
- The elements in both ranges are compared sequentially using operator== (or pred, in version (2)): A subsequence of [first1,last1) is considered a match only when this is true for all the elements of [first2,last2).
- [元素的比较是通过operator==来进行的(或者通过pred)]
- This function returns the first of such occurrences. For an algorithm that returns the last instead, see find_end.
- [该函数返回第一个与给定序列匹配的子序列,如果想要返回最后一个,请参看find_end.]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class ForwardIterator1, class ForwardIterator1>
- ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator1 first2, ForwardIterator1 last2)
- {
- if(first2 == last2) return first1; // specified in C++11
- while(first1 != last1)
- {
- ForwardIterator1 it1 = first1;
- ForwardIterator2 it2 = first2;
- while(*it1 == *it2){ // or pred(*it1, *it2) for verson 2
- ++it1; ++it2;
- if(it2 == last2) return first1;
- if(it1 == last1) return last1;
- }
- ++first1;
- }
- return last1;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- bool mypredicate(int i, int j){
- return (i==j);
- }
- int main()
- {
- std::vector<int> myvector;
- for(int i=; i<; i++) myvector.push_back(i*);
- std::vector<int>::iterator it;
- // using default comparison.
- int needle1[] = {, , , };
- it = std::search(myvector.begin(), myvector.end(), needle1, needle1+);
- if(it != myvector.end())
- std::cout<<"needle1 found at position "<<it-myvector.begin()<<'\n';
- else
- std::cout<<"needle1 not found.\n";
- // using predicate comparison.
- int needle2[] = {, , };
- it = std::search(myvector.begin(), myvector.end(), needle2, needle2+, mypredicate);
- if(it != myvector.end())
- std::cout<<"needle2 found at position "<<it-myvector.begin()<<'\n';
- else
- std::cout<<"needle2 not found.\n";
- system("pause");
- return ;
- }
- /*
- template <class ForwardIterator, class Size, class T>
- ForwardIterator search_n (ForwardIterator first, ForwardIterator last, Size count, const T& val);
- template <class ForwardIterator, class Size, class T, class BinaryPredicate>
- ForwardIterator search_n (ForwardIterator first, ForwardIterator last, Size count, const T& val, BinaryPredicate pred);
- Search range for elements
- Searches the range [first,last) for a sequence of count elements, each comparing equal to val (or for which pred returns true).
- [在[first, last)中搜索是否连续出现count次val]
- The function returns an iterator to the first of such elements, or last if no such sequence is found.
- [该函数返回指向第一个等于val的元素的迭代器,如果没有找到则返回last]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template<class ForwardIterator, class Size, class T>
- ForwardIterator search_n (ForwardIterator first, ForwardIterator last, Size count, const T& val)
- {
- ForwardIterator it, limit;
- Size i;
- limit=first; std::advance(limit,std::distance(first,last)-count); //注:私认为应该是std::advance(limit, std::distance(first, last)-count+1)
- while (first!=limit)
- {
- it = first; i=0;
- while (*it==val) // or: while (pred(*it,val)) for the pred version
- { ++it; if (++i==count) return first; }
- ++first;
- }
- return last;
- }
- */
- #include <iostream> // std::cout
- #include <algorithm> // std::search_n
- #include <vector> // std::vector
- bool mypredicate (int i, int j) {
- return (i==j);
- }
- int main () {
- int myints[]={,,,,,,,};
- std::vector<int> myvector (myints,myints+);
- std::vector<int>::iterator it;
- // using default comparison:
- it = std::search_n (myvector.begin(), myvector.end(), , );
- if (it!=myvector.end())
- std::cout << "two 30s found at position " << (it-myvector.begin()) << '\n';
- else
- std::cout << "match not found\n";
- // using predicate comparison:
- it = std::search_n (myvector.begin(), myvector.end(), , , mypredicate);
- if (it!=myvector.end())
- std::cout << "two 10s found at position " << int(it-myvector.begin()) << '\n';
- else
- std::cout << "match not found\n";
- system("pause");
- return ;
- }
- /*
- std::count
- template <class InputIterator, class T>
- typename iterator_traits<InputIterator>::difference_type count (InputIterator first, InputIterator last, const T& val);
- Count appearances of value in range
- Returns the number of elements in the range [first,last) that compare equal to val.
- [返回[first, last)中与val相等的元素的个数]
- The function uses operator== to compare the individual elements to val.
- [该函数使用operator==来判断元素是否等于val]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class InputIterator, class T>
- typename iterator_traits<InputIterator>::difference_type
- count (InputIterator first, InputIterator last, const T& val)
- {
- typename iterator_traits<InputIterator>::difference_type ret = 0;
- while(first != last){
- if(*first == val) ++ret;
- ++first;
- }
- return ret;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- int main()
- {
- int myints[] = {, , , , , , , };
- int mycount = std::count(myints, myints+, );
- std::cout<<"10 appears "<<mycount<<" times.\n";
- std::vector<int> myvector(myints, myints+);
- mycount = std::count(myvector.begin(), myvector.end(), );
- std::cout<<"20 appears "<<mycount<<" times.\n";
- system("pause");
- return ;
- }
- /*
- template <class InputIterator, class UnaryPredicate>
- typename iterator_traits<InputIterator>::difference_type count_if (InputIterator first, InputIterator last, UnaryPredicate pred);
- Return number of elements in range satisfying condition
- [返回区间中满足条件的元素个数]
- Returns the number of elements in the range [first,last) for which pred is true.
- [返回[first, last)中使得pred返回真的元素个数]
- The behavior of this function template is equivalent to:
- [该函数模板的行为等价于以下操作:]
- template <class InputIterator, class UnaryPredicate>
- typename iterator_traits<InputIterator>::difference_type count_if (InputIterator first, InputIterator last, UnaryPredicate pred)
- {
- typename iterator_traits<InputIterator>::difference_type ret = 0;
- while(first != last)
- {
- if(pred(*first)) ++ret;
- first++;
- }
- return ret;
- }
- */
- #include <iostream>
- #include <algorithm>
- #include <map>
- #include <string>
- #include <utility>
- class stuRecord
- {
- public:
- class stuInfo
- {
- public:
- void setName(std::string m_name) {name = m_name;}
- void setAge(int m_age) {age = m_age;}
- void setAddr(std::string m_addr) {addr = m_addr;}
- std::string getName() const {return name;}
- int getAge() const {return age;}
- std::string getAddr() const {return addr;}
- private:
- std::string name;
- int age;
- std::string addr;
- };
- private:
- int id;
- stuInfo m_stuInfo;
- public:
- stuRecord(int m_id, std::string m_name, int m_age, std::string m_addr)
- {
- id = m_id;
- m_stuInfo.setName(m_name);
- m_stuInfo.setAge(m_age);
- m_stuInfo.setAddr(m_addr);
- }
- int getId() const {return id;}
- stuInfo getStuInfo() const {return m_stuInfo;}
- };
- typedef stuRecord::stuInfo stuRI;
- bool setRange(std::pair<int, stuRI> stu)
- {
- return ((stu.second.getAge() > ) && (stu.second.getAge() < ));
- }
- int main()
- {
- stuRecord stu1(, "张三", , "上海");
- stuRecord stu2 = stuRecord(, "李四", , "上海");
- stuRecord stu3 = stuRecord(, "王五", , "深圳");
- stuRecord stu4 = stuRecord(, "赵六", , "长沙");
- stuRecord stu5 = stuRecord(, "孙七", , "广东");
- std::map<int, stuRI> mymap;
- mymap.insert(std::make_pair(stu1.getId(), stu1.getStuInfo()));
- mymap.insert(std::make_pair(stu2.getId(), stu2.getStuInfo()));
- mymap.insert(std::make_pair(stu3.getId(), stu3.getStuInfo()));
- mymap.insert(std::make_pair(stu4.getId(), stu4.getStuInfo()));
- mymap.insert(std::make_pair(stu5.getId(), stu5.getStuInfo()));
- int mycount = std::count_if(mymap.begin(), mymap.end(), setRange);
- std::cout<<"The number of students whose age between 20 and 30 is "<<mycount<<'\n';
- system("pause");
- return ;
- }
algorithm之不变序列操作的更多相关文章
- 【BZOJ-2962】序列操作 线段树 + 区间卷积
2962: 序列操作 Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 678 Solved: 246[Submit][Status][Discuss] ...
- 【BZOJ-1858】序列操作 线段树
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1961 Solved: 991[Submit][Status ...
- BZOJ 1858: [Scoi2010]序列操作( 线段树 )
略恶心的线段树...不过只要弄清楚了AC应该不难.... ---------------------------------------------------------------- #inclu ...
- [bzoj]2962序列操作
[bzoj]2962序列操作 标签: 线段树 题目链接 题意 给你一串序列,要你维护三个操作: 1.区间加法 2.区间取相反数 3.区间内任意选k个数相乘的积 题解 第三个操作看起来一脸懵逼啊. 其实 ...
- bzoj 2962 序列操作
2962: 序列操作 Time Limit: 50 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 有一个长度为n的序列, ...
- SCOI2010 序列操作
2421 序列操作 http://codevs.cn/problem/2421/ 2010年省队选拔赛四川 题目描述 Description lxhgww最近收到了一个01序列,序列里面包含了n个 ...
- bzoj1858[Scoi2010]序列操作 线段树
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 3079 Solved: 1475[Submit][Statu ...
- BZOJ_1858_[Scoi2010]序列操作_线段树
BZOJ_1858_[Scoi2010]序列操作_线段树 Description lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询 ...
- BZOJ1500: [NOI2005]维修数列 [splay序列操作]【学习笔记】
以前写过这道题了,但我把以前的内容删掉了,因为现在感觉没法看 重写! 题意: 维护一个数列,支持插入一段数,删除一段数,修改一段数,翻转一段数,查询区间和,区间最大子序列 splay序列操作裸题 需要 ...
随机推荐
- leetcode 110
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- 【转】Linux模式设计5-位图操作
通过位图提供的两种状态可以在非常节约内存的情况下表示开关变量,并且同类这类变量可以紧凑而高效的统一进行处理.有很多内核子系统都需要位图的支持,但是不同的情况又需要不同的位图个数,比如SMP系统上的CP ...
- [leetcode]_Remove Duplicates from Sorted Array II
题目:一个有序数组,要求保证数组中的每个元素不能超过2个. 输入:A = [1,1,1,2,2,3] 输出:length = 5, and A is now [1,1,2,2,3] 思路:双指针 ...
- 2)main函数在执行前和执行后有哪些操作
main函数执行之前,主要就是初始化系统相关资源: 1. 设置栈指针 2. 初始化static静态和global全局变量,即data段的内容 3. 将未初始化部分的全局变 ...
- PHP实例 表单数据插入数据库及数据提取 用户注册验证
网站在进行新用户注册时,都会将用户的注册信息存入数据库中,需要的时候再进行提取.今天写了一个简单的实例. 主要完成以下几点功能: (1)用户进行注册,实现密码重复确认,验证码校对功能. (2)注册成功 ...
- 黑白棋游戏 (codevs 2743)题解
[问题描述] 黑白棋游戏的棋盘由4×4方格阵列构成.棋盘的每一方格中放有1枚棋子,共有8枚白棋子和8枚黑棋子.这16枚棋子的每一种放置方案都构成一个游戏状态.在棋盘上拥有1条公共边的2个方格称为相邻方 ...
- C# 平时碰见的问题【2】
问题1 修改命名空间后 .ashx 类型创建失败 [情景] 在调整前后台项目结构的时候,修改了默认命名空间(XXX.Admin 修改成XXX.Web),结果调试的时候发现XXX.Admin.Ajax. ...
- Eclipse 4.6 Neon, could not create the java virtual machine
下了eclipse 4.6,打开报错:could not create the java virtual machine. a fatal exception has occurred. 命令行用 e ...
- STM32F0_新建软件工程详细过程
前言 由于ST公司推出比STM32F1性价比更高的F0芯片,现在市面上F0芯片的占有率也非常高.F0芯片属于M0内核,主频48M(当然,可以超频的,但尽量不要超的太多),资源大小可根据项目需求来选型. ...
- 17.python自定义函数
什么是函数,函数说白了就是将一系列代码封装起来,实现代码的重用. 什么是代码重用? 假设我有这样的需求: 但是我还是觉得太麻烦了,每次想吃饭的时候都要重复这样的步骤.此时,我希望有这样的机器: