上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 67 下一页
摘要: $30$分水题~。 检查所有节点(除了根节点)和它的父节点的关系,判断是否破坏最大堆或者最小堆的性质。 const int N=1010; int heap[N]; bool maxheap,minheap; int n; void dfs(int u,vector<int> &post) { if 阅读全文
posted @ 2021-03-11 22:02 Dazzling! 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 题意 给出一个初始序列,可以对它使用插入排序或堆排序法进行排序。现在给出一个序列,试判断它是由插入排序还是堆排序产生的,并输出下一步将会产生的序列。 思路 本题与A1089非常类似,需要直接模拟插入排序和堆排序的每一步过程。 具体做法为:先进行插入排序,如果执行过程中发现与给定序列吻合,那么说明是插 阅读全文
posted @ 2021-03-11 21:34 Dazzling! 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 手写堆排序。 const int N=1e5+10; int heap[N],cnt; int n,m; void down(int u) { int j=u*2; while(j <= n) { if(j < n && heap[j] > heap[j+1]) j++; if(heap[u] > 阅读全文
posted @ 2021-03-11 20:37 Dazzling! 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 手写堆。 const int N=1e6+10; int heap[N]; int n,m; void up(int u) { while(u/2 && heap[u] < heap[u/2]) { swap(heap[u],heap[u/2]); u/=2; } } void down(int u 阅读全文
posted @ 2021-03-11 20:21 Dazzling! 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 如果查找了 TSize 次,每次查找的位置上均有数,但都不等于要查找的数,则认为查找时间是 TSize+1。 const int N=1e4+10; int Tsize,n,m; int h[N]; int cnt; bool isprime(int x) { if(x < 2) return fa 阅读全文
posted @ 2021-03-11 19:36 Dazzling! 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 用$set$存图。 注意点 A在寻找同性朋友时,需要避免找到他想要的伴侣B,所以当当前朋友就是B或者B的同性朋友就是A时舍弃该结果。 负号标记的是女生。如果用int接收,-0000和0000对于int来说都是0,无法判断出0000的性别,所以考虑用字符串接收。 const int N=1e4+10; 阅读全文
posted @ 2021-03-11 18:02 Dazzling! 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 染色法判断是否为$k$染色图,需要一个$vis$数组防止走环路。 const int N=10010; vector<int> g[N]; bool vis[N]; int color[N]; int n,m,q; bool dfs(int u) { vis[u]=true; for(int i=0 阅读全文
posted @ 2021-03-11 16:56 Dazzling! 阅读(29) 评论(0) 推荐(0) 编辑
摘要: 每个位置至多只会被点击一次 若固定了第一行,则满足题意的点击方案至多只有一种。原因:当第i行某一位为1时,若前i行已被固定,只能点击第i+1行该位置上的数字才能使第i行的这一位变成0,从上到下使用归纳法可得上述结论。 点击的先后顺序不影响最终结果。 于是,我们不妨先考虑第一行如何点击。在枚举第一行的 阅读全文
posted @ 2021-03-09 19:20 Dazzling! 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 考察并查集的熟练使用。 const int N=10010; struct Node { int id; int father,mother; int k; int child[6]; }a[1010]; struct Answer { int id; int cnt; double sets; d 阅读全文
posted @ 2021-03-08 21:44 Dazzling! 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 最长回文子串。 动态规划解法,时间复杂度:\(O(n^2)\)。 const int N=1010; bool f[N][N]; string s; int main() { getline(cin,s); int res=0; for(int i=s.size()-1;i>=0;i--) for( 阅读全文
posted @ 2021-03-08 19:25 Dazzling! 阅读(24) 评论(0) 推荐(0) 编辑
上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 67 下一页