随笔分类 - ACM
摘要:http://blog.csdn.net/hitwhylz/article/details/10122617看到这种要计算二进制什么鬼的,就自然而然想到用位运算//二进制中1的个数#include using namespace std;int main(){ int num,count=0; ci...
阅读全文
摘要://最大子序列和(连续)://http://my.oschina.net/itblog/blog/267860#include using namespace std;int MaxSum(int* a, int n){ int sum = 0; int max = 0; //...
阅读全文
摘要://最短路径/*dijkstraDijkstra(迪杰斯特拉)算法的核心思想是贪心策略+动态规划http://www.programgo.com/article/4721147659/Dijkstra算法能得出最短路径的最优解,但是效率低*/Floyed 算法: Floyed算法比较简单,其思想可...
阅读全文
摘要:#include#includeusing namespace std;string a,b;int dp[505][505];int main(){ while(cin>>a>>b) { int len1=a.length(); int len2=b.len...
阅读全文
摘要:#include using namespace std;#include void lcs(int **A,const string &x,const string &y){ int m=x.size(); int n=y.size(); if(m=A[m][n-1]) ...
阅读全文
摘要:#include using namespace std;typedef int DataType;struct SeqList{ int MAXNUM; int n; DataType *element;};typedef struct SeqList *PSeqList;PSe...
阅读全文
摘要://链表:#include using namespace std;//定义结点:struct NODE{ int data;//数据域 NODE *next;//指针域};//链表类:class LIST{ NODE *head;public: //构造函数 LIST...
阅读全文
摘要:#include #include typedef struct PolyNode *PtrToNode; //定义链表节点,也就是多项式中的某一项; typedef struct PolyNode { int Coeff; int Exponent; PtrToNo...
阅读全文
摘要://二叉树#include#include#includeusing namespace std;//二叉树结点typedef struct BiTNode{ char data; struct BiTNode *lchild,*rchild;}BiTNode,*BiTree;//按先序...
阅读全文
摘要://DFS:油田问题#include using namespace std;char grid[101][101];int n,m;//一个网格的8个方向int dir[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}...
阅读全文
摘要:一、一个数组里除了一个数字之外,其他的数字都出现了两次 用异或来解#include using namespace std;int main(){ int T; int n,m; while(cin>>T,T){ cin>>n; while...
阅读全文
摘要:/*编程之美系列:*///01 一的数目:#includeusing namespace std;//暴力:/*int f(int n){ int count=0; while(n) { if(n%10==1) { count++; ...
阅读全文
摘要://大数加法/*1、输入,char转int,然后反转数组2、找长度长的为相加后数组的长度3、相加得到的数据可以放在一个新的数组里,也可以放在长度长的那个数组里(这时候要注意长度)4、我傻逼了,其实直接相加,不管a[i]+b[j]得到的数大于9,因为一个数组元素存放的数有 int那么大呢5、对相加后的...
阅读全文
摘要:最短路径法: 算法的主要思想是:单独一条边的路径也不一定是最佳路径。 从任意一条单边路径开始。所有两点之间的距离是边的权的和,(如果两点之间没有边相连, 则为无穷大)。 对于每一对顶点 u 和 v,看看是否存在一个顶点 w 使得从 u 到 w 再到 v 比己知的路径更短。如果是更新它。 先把所有的...
阅读全文
摘要:二分搜索算法就是把要搜索的数据在搜索文本中根据情况进行折半,比如要在2 6 4 9 3 8 7 3 5中找到找到4的位置,那么可以考虑先把数据进行排序,然后把拍好后的数据的中间的那个数据和要查找的数据4进行比较,如果中间的数据比4大,那么4肯定在左半边(即最小数据到中间数据这边),既然这样,那又...
阅读全文
摘要:转一个搞ACM需要的掌握的算法.要注意,ACM的竞赛性强,因此自己应该和自己的实际应用联系起来. 适合自己的才是好的,有的人不适合搞算法,喜欢系统架构,因此不要看到别人什么就眼红, 发挥自己的长处,这才是重要的.第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常...
阅读全文

浙公网安备 33010602011771号