PAT1013】的更多相关文章

//采用不同的图存储结构结构邻接矩阵.邻接表分别dfs,我想我是寂寞了吧,应该试试并查集,看见可以用并查集的就用dfs,bfs代替......怕了并查集了 //邻接矩阵dfs #include<cstdio>#include<algorithm>using namespace std;const int maxn=1001;int g[maxn][maxn];int n,tmp;bool vis[maxn];void dfs(int v){ vis[v]=true; for(int…
#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn=1001;int mp[maxn][maxn],vis[maxn];int n,m,k;void dfs(int s){ vis[s]=1;//置访问位,深度递归其后续节点: int i; for(i=1;i<=n;i++) { if(vis[i]==0&&mp[s][i]>0…
这道题目的意思是:在战争时代,如果一个城市被敌人占领了,那么和该城市相连的道路都必须关闭,我们必须把剩下的城市(即不包括被敌人占领的城市)连接起来. 举个例子,我们有3个城市,C1,C2,C3,C1和C2相连,C1和C3相连.如果C1被敌人占领了,那么C2,C3就孤立了,C1是敌人的城市了,C2,C3是我们的城市,那么在C1被敌人占领的情况下,我们需要修一条路,即C2---C3之间连接起来…
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that cit…
思路: 打印素数表 然后找出对应区间[m,n]中的素数 #include <iostream> #include <vector> #include <cmath> using namespace std; vector<int> v; bool IsSu(int x) //判断是否是素数 { ; i <= sqrt(x); ++i) ) return false; return true; } int main() { ; ) { ) break;…
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that cit…
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that cit…
https://www.patest.cn/contests/pat-b-practise/1013 #include "stdio.h" #include "math.h" int main() { int n, m, k, i, j, t = 0; int num[10000] = {0}; scanf("%d %d", &n, &m); k = m/n + 1; for(i = 2; t < m; ++i) { for…
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of…