c++算法
奔跑的年糕
每天都要进步一点
展开
-
贪心算法实现背包问题(背包可拆分)
#include #include using namespace std; struct Goods{ int weight; int value; double per;//单位重量的价值 double load;//装多少权重 }; //定义sort函数比较器 int compare(Goods const&a,Goods const&b){ if(a.per>b原创 2017-11-01 20:33:34 · 2583 阅读 · 0 评论 -
贪心算法 活动规划问题
#include using namespace std; //定义活动结构体,属性为起始时间和结束时间 struct act{ int begin; int end; }; int compare(act const&a,act const &b){ if(a.end>b.end){ return 1; }else retu原创 2017-11-01 21:20:36 · 330 阅读 · 0 评论 -
贪心算法 找钱问题
#include #include using namespace std; const int N=7; int Count[N]={1,3,2,0,1,2,3}; int coin[N]={1,2,5,10,20,50,100}; int backMoney(int money){ int number=0; for(int i=N-1;i>=0;i--){ int c=min原创 2017-11-01 21:48:49 · 1928 阅读 · 0 评论 -
分治算法 快速排序
快速排序 引用了点击打开链接的教程,非常容易理解 #include using namespace std; void quicksort(int a[],int left,int right){ int i,j,t,temp; if(left>right){ return ; } temp=a[left]; i=le原创 2017-11-02 21:50:00 · 231 阅读 · 0 评论 -
贪心算法棋盘覆盖
#include using namespace std; const int BOARD_SIZE=8; static int pile=1; static int BOARD[BOARD_SIZE][BOARD_SIZE]; //tr:棋盘左上角行号 //tc:棋盘左上角列号 //dr:特殊方格行号 //dc:特殊方格列号 //pile:L形块号码 // void ch原创 2017-11-02 21:52:25 · 513 阅读 · 0 评论