摘要: 算法分析的一般步骤: 1、文字描述:如果一个算法文字描述不清楚,就说明思路不清楚,也不可能写好。 prim算法是实现图的最小生成树。既然是图,就假设包含n个顶点,m条边。prim算法是从顶点出发的,其算法时间复杂度与顶点数目有关系。 (注意:prim算法适合稠密图,其时间复杂度为O(n^2),其时间 阅读全文
posted @ 2018-11-29 22:55 听风不成泣 阅读(1529) 评论(0) 推荐(0) 编辑
摘要: 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先。 输入输出格式 输入格式: 第一行包含三个正整数N、M、S,分别表示树的结点个数、询问的个数和树根结点的序号。 接下来N-1行每行包含两个正整数x、y,表示x结点和y结点之间有一条直接连接的边(数据保证可以构成树)。 接下来M行 阅读全文
posted @ 2018-09-25 11:08 听风不成泣 阅读(335) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://nanti.jisuanke.com/t/31452 思路:首先,十以内的质数:2、3、5、7。然后一百以内的,2只且只能和3搭配即23,5同理,所以只剩下了3、7。但每个质数不能出现两次(当然1有些时候可以出现两次,但1不是质数呀)否则子序列就是合数了。 在两位数的基础上 阅读全文
posted @ 2018-09-08 20:08 听风不成泣 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://www.jisuanke.com/contest/1556/105551 代码如下: 1 #include <iostream> 2 #include <bits/stdc++.h> 3 using namespace std; 4 const int maxn = 1e5 阅读全文
posted @ 2018-09-08 19:04 听风不成泣 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Tira would like to join a multiplayer game with n other players. Each player has a character with some features. There are a total of k features, 阅读全文
posted @ 2018-09-06 22:30 听风不成泣 阅读(454) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Ahlaam is a computer science student, doing her master thesis on a bioinformatics project about MicroRNAs, special molecule types found in cells. 阅读全文
posted @ 2018-09-06 22:24 听风不成泣 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, 阅读全文
posted @ 2018-09-03 20:20 听风不成泣 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Given a registry of all houses in your state or province, you would like to know the minimum size of an axis-aligned square zone such that every 阅读全文
posted @ 2018-09-02 22:58 听风不成泣 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题目描述 The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; con 阅读全文
posted @ 2018-09-02 22:53 听风不成泣 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 将N!表示成 N! = p1^t1*p2^t2*…pi^ti…*pk^tk(其中p1,p2……pk是素数,1<N<= 10^6) 显然很容易通过素数筛选求出pi,因为1<pi<=N,关键是如何快速地求出ti。 我们先来看一下对于2这个素因子,把N!分成两部分,即奇偶两部分 假设N是偶数 N! =1* 阅读全文
posted @ 2018-09-01 20:18 听风不成泣 阅读(328) 评论(0) 推荐(0) 编辑