02 2014 档案
摘要:#include using namespace std;const int maxn = 1000;int f[maxn]={0};int n,e;int a[maxn][maxn]={0};void prim(int v0) { int cost[maxn]; for (int i=0;i> n >> e; for (int i=0;i> p >> q; cin >> a[p][q]; a[q][p]=a[p][q]; } prim(1);}
阅读全文
摘要:题目描述Xiao Ming is a 2013-BUCTer.This time he has a Programming Contest for 2013th.So he has a lot of things to do recently.Attending classes,doing homework,programing,playing etc.In order to do things more efficient,he makes a time schedule,which has a start time and a end time,but no time of durati.
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn = 10000; 4 int a[maxn][maxn]; 5 int v,e; 6 void prim(int v0) { 7 int flag[maxn] = {0}; 8 int pos; 9 flag[v0] = 1;10 for (int i = 0;i > v >> e;28 for (int i = 0;i > p >> q;30 cin >> a[p][q];31 a[q][p]=a[p][q];32 ...
阅读全文
摘要://哈夫曼(最优二叉树)方法 建树//非指针做法//数据如果很大的话,有可能会超时#include #define maxn 10000+10000+3using namespace std;class T {public: int data,parent,left,right;}tree[maxn];int f[maxn] = {0};int search (int k) { int min1 = 99999999; int pos; for (int i = 0;i> n; for (int i=0; i> tree[i].data; } Huff...
阅读全文
摘要://优先队列方法#include #include #define maxn 100005using namespace std;int main () { int n; long long ans = 0; int a[maxn],b[maxn]={0}; cin >> n; for (int i=0;i> a[i]; } sort (a,a+n); a[n] = 999999999; a[n+1] = 999999999; int fa=0,fb=0,ok,pos_b=0,sum; for (int i=0;i<n-1;i+...
阅读全文
摘要:题目描述A sequence of N positive integers (10 #include using namespace std;const int maxn = 100005;int length(int *a,int len,int k) { int top = 0,mini = maxn; int sum = 0; int pos = 0; while (top = k) { mini = min (mini,top-pos); sum -= a[pos++]; } if (top...
阅读全文
摘要://upper_bound 在数列1 2 3 4 5 6中 upper_bound(3) 返回的位置为4//lower_bound 返回的值为3//此算法 是 贪心和二分查找的升级版#include #include #include using namespace std;const int maxn = 100000;int dp[maxn],s[maxn],a[maxn];void DP(int *s,int *dp,int n) { // s 中存的是最长的上升子序列;dp[i]存的是第i个数为结尾的最长上升子序列; int top=0,temp; s[top++] = a...
阅读全文
摘要://a * b % c == (a % c) * (b % c)//上面的是一个公式,接下来将介绍另一个公式,在介绍公式之前,先来看一个有关二进制的东西,那10进制数 11 来说 把11转为二进制1011,也就是2^3 + 2^1 + 2^0;在介绍一个初中的公式,a^(a1+a2+a3+……+an)==a^a1 * a^a2 * a^a3 *……* a^an;好有了这些预备知识,现在来讲重点//要求 a ^ b % c 这个结果该怎么做呢? 首先将 b 拆成 二进制,然后就会出现a1+a2+a3+……+an,所以a ^ b % c == a ^ (a1 + a2 +a3+……+an) % .
阅读全文
摘要://刚开始接触"细胞统计"这道题时是在学习栈和队列时接触的,但是经过知识的拓展,我又掌握了用并查集解决此题的算法,下面是我给出的题目和代码。//一矩形阵列由数字0到9组成,数字1到9代表细胞,//细胞的定义为沿细胞数字上下左右还是细胞数字//则为同一细胞,求给定矩形阵列的细胞个数。//如阵列://4 10//0 2 3 4 5 0 0 0 6 7//1 0 3 4 5 6 0 5 0 0//2 0 4 5 6 0 0 6 7 1//0 0 0 0 0 0 0 0 8 9//有4个细胞。//输入:整数m,n(m行,n列using namespace std;const int
阅读全文
摘要:题目描述单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合部分合为一部分,例如beast和astonish,如果接成一条龙则变为beastonish,另外相邻的两部分不能存在包含关系,例如at和atide间不能相连。输入格式输入的第一行为一个单独的整数n(n#include #include using namespace std;const int maxn = 1000;char str[maxn][maxn];int mark[maxn] = {0}
阅读全文
摘要://在学习最小生成树时,我刚接触的是并不是Kruskal算法,而是prim算法,prim算法的代码将在以后的随笔中给出。//我的第一个并查集的程序就是最小生成树Kruskal算法,我个人觉得并查集是个好东西下面就是我给出的题目描述和代码。//[题目描述]// 输入n,m,n代表村子的数目,m表示村子之间路的条数,接下来m行,没行三个整数,x,y,d,起始位置,和这两个村子的距离,//输出联通所有村子的最小路径。//样例输入//5 7//1 5 23//1 4 5//1 2 17//2 4 10//2 3 30//3 4 24//3 5 7//样例输出//45#include #inclu...
阅读全文
摘要://警察抓到了n个罪犯,警察根据经验知道他们属于不同的犯罪团伙,却不能判断有多少个团伙,//但通过警察的审讯,知道其中的一些罪犯之间相互认识,已知同一犯罪团伙的成员之间直接或间接认识。//有可能一个犯罪团伙只有一个人。请你根据已知罪犯之间的关系,确定犯罪团伙的数量。已知罪犯的编号从1至n。//输入:...
阅读全文
摘要://[问题描述]// 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n)。从 n 个整数中任选 k 个整数相加,可分别得到一系列的和。//例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为:// 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34。// 现在,要求你计算出和为素数共有多少种。// 例如上例,只有一种的和为素数:3+7+19=29)。//[输入]:// 键盘输入,格式为:// n , k (1#include using namespace std;const in...
阅读全文
摘要://为了巩固总结自己所学的知识,特意写下此博客,如有不当之处希望大神们多多批评////题目分析:// 使皇后们不在同一列,同一行,同一斜行。// 用数组mark[]标记 数组的下标来表示行,数组的值是列,// 那么斜行又分为两种情况,主对角线,cur+mark[cur],副对角线,cur-mark[cur]//Example 1 //通过行来查找。所以mark[cur]便是列。#include using namespace std;const int maxn=10000;int n,tot = 0,mark[maxn]={0};void search(int cur) ...
阅读全文

浙公网安备 33010602011771号