STL/Algorithm
文章平均质量分 50
chainyu
死ぬ気でやれよ、死なねーから!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PE54 - 备份,回家继续思考
/* High Card: Highest value card. One Pair: Two cards of the same value. Two Pairs: Two different pairs. Three of a Kind: Three cards of the same value. Straight: All cards are consecutive values. Flush: All cards of the same suit. Full House原创 2010-06-02 17:28:00 · 571 阅读 · 0 评论 -
mem_fun和mem_fun_ref的用法
<br />#include <iostream> #include <vector> #include <Windows.h> #include <algorithm> #include <functional> using namespace std; class M { public: int test() { cout << "done" << endl; return 0; } }; int main() { vector<M*> vp(3); for_each(原创 2010-10-12 11:39:00 · 597 阅读 · 0 评论 -
copy_if的正确实现
<br />// 一个copy_if的正确实现 template<typename InputIterator, typename OutputIterator, typename Predicate> OutputIterator copy_if( InputIterator begin, InputIterator end, OutputIterator destBegin,原创 2010-10-11 15:58:00 · 480 阅读 · 0 评论 -
PE92
<br />/* A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44→32→13→10→1→1 85→89→145→42→20→4→16→37→58→89 Therefore any chain that arrives at 1 or 89原创 2010-09-27 15:59:00 · 407 阅读 · 0 评论 -
C实现N!的算法
<br />#include <stdio.h> #define N 10000 int main(int argc, char **argv) { int data[N] = {1}; int digit, i, index, carry; int tmp; for (i=2, digit=0; i<=10000; i++) //计算1000! { for(index=0, carry=0; index<=digit; index++) { tmp=data原创 2010-09-09 15:25:00 · 582 阅读 · 0 评论 -
测试对Vector容器,遍历元素删除满足条件元素,而进行Erase()操作的效率
<br />#include <Windows.h> #include <iostream> #include <vector> #include <cstdlib> using namespace std; void printVect(const vector<int> &v) { for(vector<int>::const_iterator it=v.begin(); it!=v.end(); ++it) { cout << *it << ','; } } void原创 2010-08-17 21:00:00 · 1557 阅读 · 0 评论 -
对快速排序算法测试
<br />#include <algorithm> #include <cmath> #include <time.h> #include <Windows.h> #include <iostream> using namespace std; typedef long long int _INT64; const int len = 100000; _INT64 x[len] = {0}; void getRandArrayNoRepeat() { for (int i=0; i原创 2010-06-12 16:07:00 · 903 阅读 · 1 评论 -
对插入排序算法的测试
<br />#include <algorithm> #include <cmath> #include <time.h> #include <Windows.h> #include <iostream> using namespace std; typedef long long int _INT64; const unsigned len = 10000; _INT64 x[len] = {0}; void getRandArrayNoRepeat() { for (unsign原创 2010-06-12 10:23:00 · 457 阅读 · 0 评论 -
对产生不重复随机数组的算法测试
<br />算法1:<br />void getRandArrayNoRepeat() { srand( time(NULL) ); std::set<int> intSet; int temp = 0; for (unsigned i=0; i<len; ++i) { while(true) { temp = rand(); if(!intSet.count(temp)) { arr[i] = temp; intSet.inse原创 2010-06-11 11:06:00 · 570 阅读 · 0 评论 -
对二分搜索算法的测试
<br />#include <cmath> #include <time.h> #include <Windows.h> #include <iostream> using namespace std; typedef long long int _INT64; const unsigned len = 10000000; _INT64 arr[len] = {0}; void getArrayNoRepeat() { for (unsigned i=0; i<len; ++i)原创 2010-06-11 14:09:00 · 468 阅读 · 0 评论 -
二分查找
<br />测试代码<br />#include <iostream> #include <stdio.h> using namespace std; /* Return (any) position if t in sorted x[0..n-1] or -1 if t is not present */ int binarySearch(int t, int n); int *x = new int[10]; int main() { int n, t; whil原创 2010-06-07 21:55:00 · 488 阅读 · 0 评论 -
Shell排序
<br />#include <iostream> #include <vector> #include <windows.h> using std::vector; template<class T> void shell_sort(vector<T> &v) //Shell sort { const int n = v.size(); for(int gap=n/2; 0<gap; gap/=2) for(int i=gap; i<n; ++i) for(int j原创 2010-08-03 13:11:00 · 443 阅读 · 0 评论 -
Shell排序
<br />#include <iostream> #include <vector> #include <windows.h> using std::vector; template<class T> void shell_sort(vector<T> &v) //Shell sort { const int n = v.size(); for(int gap=n/2; 0<gap; gap/=2) for(int i=gap; i<n; ++i) for(int j原创 2010-08-03 13:11:00 · 501 阅读 · 0 评论 -
PE37
<br />/* The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37原创 2010-06-01 15:23:00 · 513 阅读 · 0 评论 -
PE63
<br />/* ** The 5-digit number, 16807=7^5, is also a fifth power. ** Similarly, the 9-digit number, 134217728=8^9, is a ninth power. ** How many n-digit positive integers exist which are also an nth power? */ #include <iostream> #include <cmath原创 2010-07-28 16:52:00 · 499 阅读 · 0 评论 -
PE58
<br />#include <iostream> using namespace std; bool IsPrime(long long int n) { if (n==1) return false; if (n==2) return true; if (n%2==0) return false; long long int hd=8; long long int lg=6; long long int lh=8; long long int va=n-1; whi原创 2010-07-27 16:47:00 · 2264 阅读 · 0 评论 -
PE29 - 备份,回家继续思考
/* Consider all integer combinations of ab for 2≤a≤5 and 2≤b≤5: 2^2=4, 2^3=8, 2^4=16, 2^5=32 3^2=9, 3^3=27, 3^4=81, 3^5=243 4^2=16, 4^3=64, 4^4=256, 4^5=1024 5^2=25, 5^3=125, 5^4=625, 5^5=3125 If they are then placed in numerical order,原创 2010-06-28 17:05:00 · 379 阅读 · 0 评论 -
PE53
<br />/* There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In combinatorics, we use the notation, 5C3 = 10. In general, nCr = n! r!(nr)! ,where r n, n! = n(n1)...321, and原创 2010-06-02 15:56:00 · 471 阅读 · 0 评论 -
PE35 - 备份,回家继续思考
/* The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are原创 2010-06-01 17:12:00 · 480 阅读 · 0 评论 -
PE52
/* 125874を2倍すると251748となる. これは元の数125874と同じ数を含む. 2x, 3x, 4x, 5x, 6xがxと同じ数を含むような最小の正整数xを求めよ. */ #include #include #include #include using namespace std; bool Problem52(unsigned N) { set original; set doubled; for (int i=2; i原创 2010-06-02 14:38:00 · 503 阅读 · 0 评论 -
PE39
<br />/* If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120. {20,48,52}, {24,45,51}, {30,40,50} For which value of p <= 1000, is the number of solutions maximised? *原创 2010-05-31 21:19:00 · 462 阅读 · 0 评论 -
PE40
/* An irrational decimal fraction is created by concatenating the positive integers: 0.12345678910(1)112131415161718192021... It can be seen that the 12th digit of the fractional part is 1. If原创 2010-05-30 15:16:00 · 487 阅读 · 0 评论 -
PE42
/* The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... By converting each letter in a原创 2010-05-29 00:22:00 · 458 阅读 · 1 评论 -
一维离散小波算法
void CDwt::Dwt1D(double *buffer, int buflen, int hBen, int hEnd, int h1Ben, int h1End, double *h, double *g) { double *p; int m,n,tempn; p = new double [buflen];原创 2010-05-26 14:39:00 · 713 阅读 · 0 评论 -
PE49
/* The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers a原创 2010-05-25 20:47:00 · 455 阅读 · 0 评论 -
PE56
<br />/* Googol (10^100)は非常に大きな数である: 1の後に0が100個続く. 100^100は想像を絶する. 1の後に0が200回続く. その大きさにも関わらず, 両者とも桁の和は1である. a, b < 100について自然数abを考える. 桁の和の最大を答えよ. */ #include <iostream> #include <sstream> #include <string> #include <climits> usin原创 2010-07-22 11:19:00 · 2119 阅读 · 0 评论 -
PE46
/* It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. 9 = 7 + 2*1^2 15 = 7 + 2*2^2 21 = 3 + 2*3^2 25 = 7 +原创 2010-05-27 12:22:00 · 468 阅读 · 0 评论 -
PE48
/* The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317. Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.*/#include using namespace std;void problem48(int n)原创 2010-05-26 12:04:00 · 439 阅读 · 0 评论 -
PE45
/* Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle T(n) = n(n+1)/2 1, 3, 6, 10, 15, ... Pentagonal P(n) = n(3n-1)/2 1, 5, 12, 22, 35, ... H原创 2010-05-27 14:14:00 · 503 阅读 · 0 评论 -
std::vecter capacity();
做项目中遇到个奇怪的问题比如我有std::vecter v; 然后往里面backpush了10个元素;那么 size_t size = v.capacity(); //这里应该为10吧,OK那如果又这样操作了一次v.erase(first,last); //first-last的间距为3size = v.capacity(); //这时size等于多少?原创 2010-05-21 10:17:00 · 503 阅读 · 0 评论 -
PE50 - 回家继续想
/*The prime 41, can be written as the sum of six consecutive primes:41 = 2 + 3 + 5 + 7 + 11 + 13This is the longest sum of consecutive primes that adds to a prime below one-hundred.The longest原创 2010-05-24 18:07:00 · 551 阅读 · 0 评论 -
泛型算法 for_each()
#include #include template class RecordPrinter{public: void operator()(T i) { std::cout << i <<" "; }};int main(){ const int N = 5; int arr[N] = {1,2,3,4,5}; std::for_e原创 2010-05-05 11:08:00 · 487 阅读 · 0 评论
分享