#include <bits/stdc++.h> #define M 1005 using namespace std; int n; char map1[M][M]; bool vis[M][M]; int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; void dfs(int x,int y) { vis[x][y] = 1; for(int i = 0; i < 4; i++) { int dx = x + dir[i][0]; int dy =
传送门 思路: 题意大意:n条有向边,找出最大环. 我们发现,如果一个小朋友没有被任何人崇拜,那么他一定不位于环中.为此我们可以设置一个indug数组预处理.如果2被崇拜了那么indug[2]就加加,那么后续我们只需要dfs不为0的小朋友即可. 优化 可是遍历小朋友的话会有大量重复.比如1->3->5->1,我们遍历了1,那么其实3和5是不需要去管的对吧.所以就有了代码. #include <bits/stdc++.h> using namespace std; int vi
bitset可以存储二进制数位 bitset<8> x(2); cout<<x<<endl; //输出:00000010 #include <iostream> #include <bitset> using namespace std; int main() { int n, m; while (cin >> n >> m) { bitset<8> t(n);//创建对象的时候可以直接传进去一个数 cout