摘要: 和1147 Heaps (30 分)类似,$30$分水了。 const int N=1010; int heap[N]; bool minheap,maxheap; int n; void dfs(int u,vector<int> &path) { if(u*2 > n)//叶子结点 { for( 阅读全文
posted @ 2021-03-11 22:28 Dazzling! 阅读(32) 评论(0) 推荐(0) 编辑
摘要: $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) 编辑