题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa sy…
模拟bfs,以空团为起点,用堆维护当前最小的团,然后进行加点更新 在加入新点时要注意判重,并且用bitset来加速判断和转移构造 #include<bits/stdc++.h> #include<bitset> #include<queue> using namespace std; #define ll long long ][]; int n,k; ll a[]; bitset<>bit[]; struct Node{ ll w; bitset<&…
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 找第\(k\)小团. 思路 用\(bitset\)来标记每个结点与哪些结点直接有边,然后进行\(bfs\),在判断新加入的点与现在有的点是否都有边则直接用\(bitset\)与一下即可,记得去重. 代码 #include <set> #include <map> #include <deque> #include <queue> #include <stack> #include <…
Kth Minimum Clique 题目传送门 解题思路 我们可以从没有点开始,把点一个一个放进去,先把放入一个点的情况都存进按照权值排序的优先队列,每次在新出队的集合里增加一个新的点,为了避免重复,一个集合中的放入次序是按编号递增的,新放进去的点必须和已经在集合中的所有点之间都有一条边.当然我们不可能在入队时写两层循环来判断能不能放,所以用bitset,为1则说明集合里的点都和这个点之间有边,每次入队前利用&操作更新. 代码如下 #include <bits/stdc++.h> #…
链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. White Cloud can walk meters or run k meters per second. Since White Cloud is tired,it can't run for two or more continuous seconds. White Cloud will mov…
链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to n. White Rabbit wants to visit these stores to n. The store numbered i has a price a[i] representing that White Rabbit can spend a[i] dollars to buy…
White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The plant in the j-th column of the i-th row belongs the a[i][j]-th type.White Cloud wants to help White Rabbit fertilize plants, but the i-th plant can onl…
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add(x2+1,y1,-z); 我们会想为什么和一维的差这么多,我们不妨这样看 add(x1,y1,z);的更新效果 add(x2+1,y2+1,z);的更新效果 那么这个下半区有两个,我们再更新 add(x1,y2+1,-z);的更新效果 add(x2+1,y1,-z);的更新效果 最后用红的去剪掉黄色…
题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d).问飞机旅程与最后一个云层相交的x坐标.不存在 分析: 可以确定两直线联立后解得交点x=(b-d)/(a-c). 可以看做是点(a,b)和(c,d)的斜率的负数. 要求的最大的x,那么就变成了求得最小的斜率,答案最后再乘-1即可. 就是求每个(c,d)点到(a,b)的斜率,可以把每一个(a,b)看…
思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strcat itoa system("cls") #include <iostream>//pair #include <…