当前位置:网站首页>PAT1166 Summit(25)
PAT1166 Summit(25)
2022-08-01 12:51:00 【此杭非彼航】
题目
代码
参考代码(含注释)
// 不需要并查
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> edge(250, vector<int>(250, 0));
int main() {
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
edge[x][y] = edge[y][x] = 1;
}
int k;
cin >> k;
for(int i = 1; i <= k; i++) {
int l;
cin >> l;
vector<int> v(l);
for(int j = 0; j < l; j++)
cin >> v[j];
bool flag1 = true;
for(int j = 0; j < l; j++) {
for(int k = j + 1; k < l; k++){
//判断是否两两相连
//cout << v[j] << " " << v[k] << " " << edge[v[j]][v[k]] << endl;
if(edge[v[j]][v[k]] == 0) {
flag1 = false;
break;
}
}
if(flag1 == false) break;
}
bool flag2 = false;
int minn = -1;
for(int j = 1; j <= n; j++) {
//从最小的序号开始找
int k;
for(k = 0; k < l; k++) {
if(v[k]==j) break;//结点已经在给定的集合中,退出
if(v[k]!=j && edge[j][v[k]] == 0) break;//结点不在,但和集合中的点不全相连,退出
}
if(k == l) {
//如果上面那个循环顺利结束
flag2 = true;
minn = j;
break;
}
}
if(flag1 == false) printf("Area %d needs help.\n", i);
else if(flag2) printf("Area %d may invite more people, such as %d.\n", i, minn);
else printf("Area %d is OK.\n", i);
}
}
复现代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,k;
cin>>n>>m;
int vis[n+1][n+1];
memset(vis,0,sizeof(vis));
while(m--){
int x,y;
cin>>x>>y;
vis[x][y]=vis[y][x]=1;
}
cin>>k;
for(int t=1;t<=k;t++){
int l,flag1=1,flag2=1;
cin>>l;
int a[l];
for(int i=0;i<l;i++){
cin>>a[i];
}
for(int j=0;j<l;j++){
//判断是否两两相连
for(int k=j+1;k<l;k++){
if(vis[a[j]][a[k]]==0){
flag1=0;
break;
}
}
if(flag1==0) break;
}
if(!flag1){
printf("Area %d needs help.\n",t);
continue;
}
int pos=-1;
for(int i=1;i<=n;i++){
//从序号最小的点开始判断
int j;
for(j=0;j<l;j++){
if(a[j]==i||vis[i][a[j]]==0){
//在集合中或者不相连,退出
break;
}
}
if(j==l){
pos=i;
flag2=0;
break;
}
}
if(flag2==0) printf("Area %d may invite more people, such as %d.\n",t,pos);
else printf("Area %d is OK.\n",t);
}
}
参考文章
边栏推荐
- 脚本语言Lua的基础知识总结
- Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!
- 如何使用OpenCV测量图像中物体之间的距离
- SQL functions STR
- 观察者模式
- The obstacles to put Istio into production and how we solve them
- CloudCompare & PCL ICP registration (point to face)
- 找出相同属性值的对象 累加数量 汇总
- 8. SAP ABAP OData 服务如何支持创建(Create)操作
- NebulaGraph v3.2.0 Performance Report
猜你喜欢
8. How does the SAP ABAP OData service support the Create operation
Batch replace tables in Word with pictures and save
50W+小程序开发者背后的数据库降本增效实践
PyTorch 进阶之路:在 GPU 上训练深度神经网络
嵌入式开发:创建和使用可移植类型的7个技巧
win10系统重装,无法登录进行同步的情况下chrome数据恢复
库函数的模拟实现(strlen)(strcpy)(strcat)(strcmp)(strstr)(memcpy)(memmove)(C语言)(VS)
postgresql之page分配管理(一)
Multi-threaded cases - blocking queue
Find objects with the same property value Cumulative number Summarize
随机推荐
并发编程10大坑,你踩过几个?
LeetCode_位运算_简单_405.数字转换为十六进制数
PyTorch 进阶之路:在 GPU 上训练深度神经网络
MMF的初步介绍:一个规范化的视觉-语言多模态任务框架
Meshlab&Open3D SOR滤波
【无标题】
什么是一致性哈希?可以应用在哪些场景?
【StoneDB Class】入门第二课:StoneDB 整体架构解析
深入解析volatile关键字
实现集中式身份认证管理的案例
求方阵的无穷范数「建议收藏」
阿里云官方 Redis 开发规范
windows IDEA + PHP+xdebug 断点调试
SQL函数 SQRT
Windows 安装PostgreSQL
tensorflow2.0 handwritten digit recognition (tensorflow handwriting recognition)
What is consistent hashing?In what scenarios can it be applied?
快速理解拉格朗日乘子法
Software designer test center summary (interior designer personal summary)
故障007:dexp导数莫名中断