![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
罚酒饮得
这个作者很懒,什么都没留下…
展开
-
贪心算法--活动安排问题
#include <bits/stdc++.h>using namespace std;struct act{ int start;//开始时间 int end;//结束时间 int tag;//用于标记是第几个活动 }acts[100];bool cmp(const act &a,const act &b){ return a.end<...原创 2020-04-15 14:28:16 · 199 阅读 · 0 评论 -
贪心算法--最大整数问题
#include <iostream>#include <string>#include <sstream>using namespace std;string str[100]="";string ChangeIntToString(int num){ stringstream ss; string s;//用来放转换成string的数值 ...原创 2020-03-27 15:14:18 · 1183 阅读 · 0 评论 -
动态规划--0/1背包问题
#include <iostream>#include <algorithm>using namespace std;int w[5]={0,2,7,3,8};int v[5]={0,4,4,3,6};int Space[5][9]={};int bag=8;int main(){ for(int i=1;i<5;i++){ for(int ...原创 2020-03-26 16:04:42 · 86 阅读 · 0 评论 -
递归与分治--快速排序算法
#include <iostream>using namespace std;void QuickSort(int a[],int begin,int end){ if(begin<end){ int pivot=a[begin]; int l=begin; int r=end; while(l<r){//快速排序算法思想,最右边小于pivot则把他...原创 2020-03-26 15:15:36 · 237 阅读 · 0 评论 -
递归与分治--归并排序
#include <iostream>using namespace std;int temp[1024];//合并a[0----mid]和a[mid+1----right],并且存入temp[]数组中 void hebing(int a[],int left,int mid,int right,int temp[]){ int i,j,k,l; i=left; j=m...原创 2020-03-26 15:09:49 · 216 阅读 · 0 评论 -
棋盘覆盖问题
#include <iostream>using namespace std;#define MAX 1024int p[MAX][MAX];int id=0;void chessboard(int x,int y,int m,int n,int size){//m,n为奇异点坐标 if(size==1){ return ; } id++; int s=si...原创 2020-03-25 17:20:19 · 140 阅读 · 0 评论 -
动态规划--最大字段和问题
#include <iostream>using namespace std;int find_MAX_Sum(int n,int a[]){ int sum=0,temp=0; for(int i=0;i<n;i++){ if(temp>0) temp=temp+a[i]; else temp=a[i]; if(temp>sum)...原创 2020-03-24 14:23:59 · 162 阅读 · 0 评论 -
回溯法--骑士游历问题
基本思想就是宏观看问题,微观交给计算机自己运行。先上代码#include <iostream>using namespace std;int chess[8][8]={};int counts=0;bool ifout(int x,int y){//判断是否出界 if(x>=0&&x<=7&&y>=0&&...原创 2020-03-24 10:20:34 · 1783 阅读 · 0 评论 -
回溯法--N皇后问题
一般是八皇后,首先是算法思想如下:void generate(int n){ int col; for(col=0;col<=7;col++){ if(不冲突){ 放置,并且宣布占领 if(n<7){ generate(n+1); }else{ printf();//打印 } 回溯,取消占领. } }}主函数如...原创 2020-03-22 16:35:22 · 158 阅读 · 0 评论 -
如何利用python制作一个小游戏
1.首先创建一窗口import pygameimport pygame.locals as localspygame.init()pygame.display.set_mode((300,300))while True: #窗口无响应是因为没有任何注册在窗口上的事件 #为当前窗口增加响应事件 #利用pygame注册事件,其返回值是一个列表,存放当前注册时获...原创 2020-03-21 14:07:55 · 2497 阅读 · 0 评论 -
贪心算法--多机调度问题
#include <iostream>#include <algorithm>using namespace std;int main(){ cout<<"请输入总的机器数目:"; int m,n;//m代表总的机器数目 cin>>m; cout<<"请输入有多少个任务:"; cin>>n;//n表示任务个...原创 2020-03-20 16:10:53 · 1002 阅读 · 0 评论 -
贪心算法--钞票找零
#include <iostream>#include <algorithm>using namespace std;int main(){ int Money[6]={200,100,20,10,5,1};//定义的钞票的面额 int x=628;//总的金钱数目 int num=6;//钞票面额的数目 int count=0;//使用了多少张钞...原创 2020-03-18 16:06:09 · 159 阅读 · 0 评论 -
动态规划---斐波那契数列
1.先上代码#include <iostream>using namespace std;int x;int dp[200];int f(int x){ dp[1]=1; dp[2]=1; for(int i=3;i<=x;i++){ dp[i]=dp[i-1]+dp[i-2]; } return dp[x];}int main(){ cou...原创 2020-03-18 15:41:25 · 83 阅读 · 0 评论 -
递归与分治---汉诺塔问题
1.如何理解递归与分治呢?其主要的思想在于又宏观到微观,由整体到个体。2.不多说,上代码#include <iostream>using namespace std;//把A上的盘子放到C上 void Hanoi(int n,char A,char B,char C){ if(n==1){ cout<<A<<"-->"<<...原创 2020-03-18 15:35:16 · 156 阅读 · 0 评论 -
C++不使用头结点创建单链表,并实现删除某个结点的功能
头部声明如下#include <iostream>#include <malloc.h>using namespace std;typedef int ElemType;typedef struct LNode{ ElemType data;//存放数据元素值 struct LNode *next;}LinkNode;以下是主函数:...原创 2019-07-13 11:07:21 · 391 阅读 · 0 评论